Example #1
0
 public function move_file()
 {
     $target_path = SITE_ROOT . DS . 'public' . DS . $this->upload_dir . DS . $this->username . DS . $this->name;
     if (isset($this->new_name)) {
         $this->name = basename($this->new_name);
         $target_path = SITE_ROOT . DS . 'public' . DS . $this->upload_dir . DS . $this->username . DS . $this->name;
     }
     if (file_exists($target_path)) {
         $file = File::find_by_name($this->name);
         $this->id = $file->id;
         if ($this->update()) {
             unset($this->temp_path);
             $output = $this->name . ' was uploaded successfully';
             if (!is_null($this->new_name)) {
                 $output .= ', and was renamed ' . $this->new_name;
             }
             $output .= ".";
             $this->messages[] = $output;
             return true;
         }
         $this->messages[] = "The file {$this->name} already exists and was reuploaded.";
         return true;
     }
     if (move_uploaded_file($this->temp_path, $target_path)) {
         if ($this->create()) {
             unset($this->temp_path);
             $output = $this->name . ' was uploaded successfully';
             if (!is_null($this->new_name)) {
                 $output .= ', and was renamed ' . $this->new_name;
             }
             $output .= ".";
             $this->messages[] = $output;
             return true;
         }
     } else {
         $this->messages[] = "The file upload failed, possibly due to incorrect permissions on the upload folder.";
         return false;
     }
     $this->new_name = null;
 }