问题
I read a few threats on escaping but doesn't work. it works with a path without spaces fine.... ($subfolder contains spaces)
$subfolder = "this a subf";
$filepath = "/var/www/domain/$subfolder/$imagetodelete";
$filepath = str_replace(" ", "\ ", $filepath);
unlink($filepath); // correct if $subfolder/path contains no spaces
echo $filepath;
回答1:
$filepath = str_replace(" ", "\ ", $filepath);
The problem here is that you are escaping the space character in PHP, not actually inserting a backslash. In order to actually mean a backslash, you have to escape a backslash, like so:
$filepath = str_replace(" ", "\\ ", $filepath);
回答2:
thanks everyone very much, when I downgraded to php 5.2 it worked. without str replace . it appears to be a BUG see Php - KB
来源:https://stackoverflow.com/questions/27989096/unlink-not-working-with-space-in-foldername-path