unlink not working with space in foldername path

安稳与你 提交于 2019-12-12 03:13:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!