unlink PHP works when file is in root, not if file is in folder

梦想与她 提交于 2019-12-02 12:24:43

What about:

$root = realpath($_SERVER['DOCUMENT_ROOT']);
$myfile = '$root/images/theone.png';
unlink($myfile);

Although to my knowledge, your attempted method should work, unless either I'm missing something, or you haven't included some code here that might be interfering with the unlink.

__DIR__ - this magic constant contains current directory, in case that the file is in the same directory as your PHP script you can use:

unlink(__DIR__ . "/$myfile");

If the file is for example in one directory above your PHP script you can use:

unlink(__DIR__ . "/../$myfile");

If the directory has correct access rights it should work.

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