Example #1
0
 function copy_files()
 {
     $files = $this->get_files();
     $paths = $this->project->file_paths();
     foreach ($files as $file_parameters) {
         $file_to_copy = new File($file_parameters);
         $file_to_copy_url = $file_to_copy->path();
         //create the file record
         $file = new File();
         $file->import_parameters_exactly($file_parameters);
         //we want to create a new file  so we need to reset the id. If we don't the app will just save our changes on
         //the old file (bad idea)
         $file->set('id', null);
         $file->set('created_date', time());
         $file->set('project_id', $this->project->id);
         $file->save();
         //copy the actual file
         if (file_exists($file_to_copy_url)) {
             copy($file_to_copy_url, $paths['upload_path'] . $file->name);
         }
     }
 }