Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2010
    Location
    God's Own Country
    Posts
    87
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Unlink() - permission denied/no such file or directory error.

    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.

    PHP 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); 


  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,338
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    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.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    . 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.

    Edit:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •