开发者

PHP exec rm -Rf not working for subdirectories

I am trying 开发者_运维百科to delete all contents in specific folder but it doesn't seem to effect subfolder but it should, because bash command does it from console.

system('rm -Rf some_dir/*');


There is no need in asterisk in this command. If you want to remove directory together with files, remove the slash as well. Leaving the slash will delete files, but preserve directory.

Also check comments on this page: http://php.net/manual/en/function.unlink.php


It's probably because the user executing the script doesn't have privileges for deleting the directory(ies) or the shell isn't in the right directory.

If you're running this via apache, chances are the process is owned by www-data. If the "some_dir" directory doesn't allow for write access by www-data, then it won't work.

Since you're using a relative path (very dangerous), you need to ensure that the script is executing in the correct directory. I'd suggest you change the path to an absolute one if you can - "rm -rf /path/to/some_dir".

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜