[thelist] How do I delete uploaded files in PHP?

Anthony Baratta anthony at baratta.com
Mon Nov 12 15:09:21 CST 2007

How are your resumes being posted to the site?? Are you using the built-in PHP File Upload functions?


I'm curious as to why you are using FTP at all. Are you receiving them via the web service and the transporting them via FTP to a specific location? Are the files local to the web server?

If you login manually with your FTP credentials can you see the files you expect? Can you delete them manually?

If the files are local to the web sever, make sure that the web server has the proper permissions on the files. You should be using this PHP function on files that are local:


-----Original message-----
From: "Nan Harbison" nan at nanharbison.com
Date: Mon, 12 Nov 2007 12:55:03 -0800
To: thelist at lists.evolt.org
Subject: [thelist] How do I delete uploaded files in PHP?

> Hi all,
> I am working on a website where clients can upload a resume, and can upload
> a new resume in its place. This is working just fine. However, I am having
> the file names be randomly generated, so the old file is not overwritten. I
> need to be able to delete the old file, but I am having trouble a tutorial
> on how to do this, all the links I get in google are for little applications
> to manage file uploads and downloads.
> -I tried using 'unlink' but it didn't work
> -I tried this but it isn't working. I didn't get any error messages, it just
> doesn't delete the old resume.
> $file = 'resumes/'.$_POST['oldresume'];
> $ftp_server = 'my ftp address';
> $ftpuser = 'myusername;
> $ftppass = my password;
> // set up basic connection
> $conn_id = ftp_connect($ftp_server);
> // login with username and password
> $login_result = ftp_login($conn_id, $ftpuser, $ftppass);
> // try to delete $file
> if (ftp_delete($conn_id, $file)) { // the ftp function
>          echo '$file deleted successful';
>  } else {
>          echo 'could not delete $file';
>  }
>     // close the connection
>     ftp_close($conn_id);
> Can someone please explain to me how I should do this, or point me to a
> resource that show me?
> Thanks!
> Nan

More information about the thelist mailing list