예제 #1
0
 /**
  * Relate an existing file on the filesystem to the document.
  * Copies the file to the new destination, as defined in {@link get_DMS_path()}.
  *
  * @param String Path to file, relative to webroot.
  */
 function storeDocument($filePath)
 {
     if (empty($this->ID)) {
         user_error("Document must be written to database before it can store documents", E_USER_ERROR);
     }
     //calculate all the path to copy the file to
     $fromFilename = basename($filePath);
     $toFilename = $this->ID . '~' . $fromFilename;
     //add the docID to the start of the Filename
     $toFolder = DMS::get_storage_folder($this->ID);
     $toPath = DMS::get_dms_path() . DIRECTORY_SEPARATOR . $toFolder . DIRECTORY_SEPARATOR . $toFilename;
     DMS::create_storage_folder(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $toFolder);
     //copy the file into place
     $fromPath = BASE_PATH . DIRECTORY_SEPARATOR . $filePath;
     copy($fromPath, $toPath);
     //this will overwrite the existing file (if present)
     //write the filename of the stored document
     $this->Filename = $toFilename;
     $this->Folder = $toFolder;
     $extension = pathinfo($this->Filename, PATHINFO_EXTENSION);
     if (empty($this->Title)) {
         $this->Title = basename($filePath, '.' . $extension);
     }
     //don't overwrite existing document titles
     $this->LastChanged = SS_Datetime::now()->Rfc2822();
     $this->write();
     return $this;
 }
예제 #2
0
 /**
  * Relate an existing file on the filesystem to the document.
  *
  * Copies the file to the new destination, as defined in {@link get_DMS_path()}.
  *
  * @param string $filePath Path to file, relative to webroot.
  *
  * @return DMSDocument
  */
 public function storeDocument($filePath)
 {
     if (empty($this->ID)) {
         user_error("Document must be written to database before it can store documents", E_USER_ERROR);
     }
     // calculate all the path to copy the file to
     $fromFilename = basename($filePath);
     $toFilename = $this->ID . '~' . $fromFilename;
     //add the docID to the start of the Filename
     $toFolder = DMS::get_storage_folder($this->ID);
     $toPath = DMS::get_dms_path() . DIRECTORY_SEPARATOR . $toFolder . DIRECTORY_SEPARATOR . $toFilename;
     DMS::create_storage_folder(DMS::get_dms_path() . DIRECTORY_SEPARATOR . $toFolder);
     //copy the file into place
     $fromPath = BASE_PATH . DIRECTORY_SEPARATOR . $filePath;
     //version the existing file (copy it to a new "very specific" filename
     if (DMSDocument_versions::$enable_versions) {
         DMSDocument_versions::create_version($this);
     } else {
         //otherwise delete the old document file
         $oldPath = $this->getFullPath();
         if (file_exists($oldPath)) {
             unlink($oldPath);
         }
     }
     copy($fromPath, $toPath);
     //this will overwrite the existing file (if present)
     //write the filename of the stored document
     $this->Filename = $toFilename;
     $this->Folder = $toFolder;
     $extension = pathinfo($this->Filename, PATHINFO_EXTENSION);
     if (empty($this->Title)) {
         // don't overwrite existing document titles
         $this->Title = basename($filePath, '.' . $extension);
     }
     $this->LastChanged = SS_Datetime::now()->Rfc2822();
     $this->write();
     return $this;
 }