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

Nan Harbison nan at nanharbison.com
Mon Nov 12 15:20:09 CST 2007


I tried this ftp method as a stupid wild stab at something that might work,
I found it on a website explaining how to delete files. Resumes are uploaded
using PHP file upload functions, mainly using this function, written by
Marcos Thiago <fabismt at yahoo.com.br>:

  function moveFileToDestination(){

    if(is_uploaded_file($this->tmp_name) && $this->dst_dir){
        $dst_file_name = ($this->randon_name) ? $this->generateFileName() :
        $full_destination_path = $this->dst_dir."/".$dst_file_name;
        if(file_exists($full_destination_path) && !$this->replace) {
          $this->error_type = 7;
        } else {
            @chmod ($this->dst_dir."/".$dst_file_name,$this->file_perm);
            $this->error_type = 0; 
          } else {
            $this->error_type = 5; 
    } else {
      $this->error_type = 6; 

    if($this->error_type != 0){
= $this->name;
= $dst_file_name;
= $this->dst_dir;
= $this->fld_name;
= $this->size;
= $this->type;
= $this->error_type;
= $this->msg[$this->error_type];
      return FALSE;
    } else {
= $this->name;
= $dst_file_name;
= $this->dst_dir;
= $this->fld_name;
= $this->size;
= $this->type;
= $this->error_type;
= $this->msg[$this->error_type];
      return TRUE;
The unlink function didn't work for me. I will reread the php.net page you
sent me. 

-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Anthony Baratta
Sent: Monday, November 12, 2007 4:09 PM
To: thelist at lists.evolt.org
Subject: Re: [thelist] How do I delete uploaded files in PHP?

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


* * Please support the community that supports you.  * *

For unsubscribe and other options, including the Tip Harvester and archives
of thelist go to: http://lists.evolt.org Workers of the Web, evolt ! 

More information about the thelist mailing list