进入一个目录,然后删除文件


Go to a directory and then deletes the file

我在PHP中删除文件有问题。我有一个文件夹

"public_html"

包含我所有的文件

还有一个目录叫做

"user_images"

我的问题是我不能使用unlink()函数,因为我在public_html目录。我需要去user_images文件夹删除文件。有什么解决办法吗?谢谢你的回答。我在想chdir(),但我不知道如何使用它。

我是这么想的:

chdir("user_images");
if(chdir("user_images")){
   unlink($file_name);
}

你可以直接删除文件名和路径

$file = 'user_images/' . $file_name;
if(file_exists($file)){
 unlink($file);
}