Thread: Unlink problem

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    Unlink problem


    Hello,

    I have a problem deleting a .pdf file from the server. I get the name of the file that I want to delete from my DB and the file does exist but unlink just isn't working.
    This is my code:


    PHP Code:
    $oldF=false;
    $oldFileName "../folder/".$_POST['oldName'];                        
    if(
    file_exists($oldFileName)){
           
    $oldF=true;                                
           if(
    unlink($oldFileName)){
                  echo 
    'Deleted';
                  
    $oldF=false;
           }

    Now get the strange thing. If I refresh the site multiple times then the file will be deleted. Sometimes on the 4. refresh or 5....
    Thanks for all the help!
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    If I refresh the site multiple times then the file will be deleted. Sometimes on the 4. refresh or 5
    Are you determining whether or not the file was deleted based on whether the text 'Deleted' was printed or based on some external check?

    Is file_exists returning false or is unlink returning false?

    Do you have error reporting fully turned on?

    Also your code allows an attacker to delete arbitrary files from your server.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo