Delete file names from folder with Variables
I am trying to crea开发者_开发问答te this script that would delete the filename from a folder whose name is contained inside the $id variable. NOt sure why its not working:
Code:
unlink('/userstash/$id' . $fn);
use this one
unlink("/userstash/$id$fn");
single quotes don't parse variables inside
Use double quotes instead of single quotes, in other words:
unlink("/userstash/$id" . $fn);
Take care that you properly build the string for your path and then add some error checking so your script informs you when something goes wrong and tells you about the filename:
$path = '/userstash/' . $id . $fn:
$r = unlink($path);
if ($r === false)
{
throw new Exception(sprintf('Unable to delete file "%s".', $path));
}
You should use the double qoutes:
unlink("/userstash/$id" . $fn);
精彩评论