开发者

Delete file names from folder with Variables

开发者 https://www.devze.com 2023-03-25 08:50 出处:网络
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:

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消