...

View Full Version : Unlink() - permission denied/no such file or directory error.



sradha
02-28-2012, 09:25 AM
Hi all,

I am unable to delete a file lying in a particular directory even though the directory is writeable.

I have a folder named 'sample' which contains another sub folder named 'images' and a php file ( the file which contains the code to perform delete operation).

I am using xampp (localhost).It seems the folder path is correct and the folder is writeable too.I could list all the files lying in the directory but I am unable to delete them.

I am getting the following errors,
Warning: unlink(.) [function.unlink]: Permission denied in C:\xampp\htdocs\sample\del_file.php on line 19
..

Warning: chmod() [function.chmod]: No such file or directory in C:\xampp\htdocs\sample\del_file.php on line 16

Warning: unlink(..) [function.unlink]: Permission denied in C:\xampp\htdocs\sample\del_file.php on line 19
apache_pb.gif

Warning: chmod() [function.chmod]: No such file or directory in C:\xampp\htdocs\sample\del_file.php on line 16

Warning: unlink(apache_pb.gif) [function.unlink]: No such file or directory in C:\xampp\htdocs\sample\del_file.php on line 19


Here is my code.



$filename = './images/';
echo realpath($filename);
if (file_exists($filename)) {echo "exists";}else{echo "not exists";}

if (is_writable($filename)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}

if ($handle = opendir($filename)) {

while (false !== ($file = readdir($handle))) {

echo $file."<br/>";
//chmod("apache_pb.gif", 0777);
unlink($file);


}

closedir($handle);
}

tangoforce
02-28-2012, 10:40 AM
Sounds like an operating system permission problem. YOU might be able to delete files manually by right clicking but it doesn't mean that an automated process can - especially if its running as a system service - you might need to change its user credentials to match yours.

Windows isn't normally too bad for this but some windows systems are configured quite strictly and those that are can be quite a pain.

Fou-Lu
02-28-2012, 02:20 PM
. and .. cannot be unlinked since they don't really exist. That's the first two errors, so you need to skip those two files.
Second: unlink needs a full path. You've given it only a name. Concatenate $filename and $file and pull the realpath.


Wait no I'm wrong unlink doesn't need a fully resolved name. But you still need to concat your directory since its in a different location than this file is executing.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum