My question is almost the same as this one Deleting all files from a folder using PHP?
And I tried to use the answer provided by @Floern https://stackoverflow.com/a/4594262/2167772
But it didn't work for me. I tried to get filenames from a folder on the Linux server. And I have changed the folder and file permission to rwxrwxrwx. And I got the "Unable to get the filename" message all the time. Does anyone know how to solve it? Thanks a lot!
$files=glob('/data/in/*') or die ("Unable to get the filename");
foreach ($files as $file) {
if(is_file($file)){
echo $file;
unlink($file) or die ("Uable to delete file!");
}
}
------Update----
I just figured it out. It is the problem with the server. I cannot write anything to the data folder even I assign the write permission. I will move my in folder to another folder.
Thank you so much for everyone's comments!