First of all, your code could be more efficient:
$path = "/full/server/path/to/directory/containing/files/";
for ($i=0;$i<$num_files;$i++) {
$filename = substr(strrchr($del[$i] . "/"), 1);
echo "deleting " . filename . "...<br>";
if (@unlink($path . $del[$i])) {
echo $filename . " successfully deleted";
}
else {
echo "ERROR deleteing " . $filename;
}
echo "<br>";
}
This allows you to at least see which files are being deleted, and which aren't. The "@" symbol switches off error reporting for the function it is used on, so that users don't get an ugly error message if something goes wrong (just remove the "@" symbol to see an error message)
This code works for some users and not for others
Could you be more specific? My "doesn't work" do you mean that it doesn't delete the files?
:eek: Never set permissions to 777 -- BIG security hazard. If, ever you need to have PHP handing files, CHOWN (change owner) those files to HTTPD (or whatever your "public" user is on the server). An easy way to do this, if you don't have root/admin access on the server, is to temporarily CHMOD the directories in which these files will be located to 777. Then write up a PHP script to make directories within that directory (CHMOD'd to 755), to where the files handled by PHP will be. Then, CHMOD that main directory back to 755 (or whatever it was originally).
Even better, if you don't need to be manipulating any files, check out FTP Functions. No ownership or file permission issues are involved, making it more secure.