Пример #1
0
 protected function download(\Concrete\Core\File\File $file, $rcID = null)
 {
     $filename = $file->getFilename();
     $file->trackDownload($rcID);
     $fsl = $file->getFileStorageLocationObject();
     $configuration = $fsl->getConfigurationObject();
     $fv = $file->getVersion();
     if ($configuration->hasPublicURL()) {
         return \Redirect::url($fv->getURL())->send();
     } else {
         return $fv->forceDownload();
     }
 }
 /**
  * {@inheritDoc}
  */
 public function getFileStorageLocationObject()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getFileStorageLocationObject', array());
     return parent::getFileStorageLocationObject();
 }
Пример #3
0
 /**
  * Imports a local file into the system. The file must be added to this path
  * somehow. That's what happens in tools/files/importers/.
  * If a $fr (FileRecord) object is passed, we assign the newly imported FileVersion
  * object to that File. If not, we make a new filerecord.
  *
  * @param string $pointer path to file
  * @param string|bool $filename
  * @param ConcreteFile|bool $fr
  *
  * @return number Error Code | \Concrete\Core\File\Version
  */
 public function import($pointer, $filename = false, $fr = false)
 {
     if ($filename == false) {
         // determine filename from $pointer
         $filename = basename($pointer);
     }
     $fh = Loader::helper('validation/file');
     $fi = Loader::helper('file');
     $cf = Core::make('helper/concrete/file');
     $sanitizedFilename = $fi->sanitize($filename);
     // test if file is valid, else return FileImporter::E_FILE_INVALID
     if (!$fh->file($pointer)) {
         return Importer::E_FILE_INVALID;
     }
     if (!$fh->extension($filename)) {
         return Importer::E_FILE_INVALID_EXTENSION;
     }
     if ($fr instanceof File) {
         $fsl = $fr->getFileStorageLocationObject();
     } else {
         $fsl = StorageLocation::getDefault();
     }
     if (!$fsl instanceof StorageLocation) {
         return Importer::E_FILE_INVALID_STORAGE_LOCATION;
     }
     // store the file in the file storage location.
     $filesystem = $fsl->getFileSystemObject();
     $prefix = $this->generatePrefix();
     try {
         $src = fopen($pointer, 'rb');
         $filesystem->writeStream($cf->prefix($prefix, $sanitizedFilename), $src, array('visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => Core::make('helper/mime')->mimeFromExtension($fi->getExtension($sanitizedFilename))));
     } catch (\Exception $e) {
         return self::E_FILE_UNABLE_TO_STORE;
     }
     if (!$fr instanceof File) {
         // we have to create a new file object for this file version
         $fv = ConcreteFile::add($sanitizedFilename, $prefix, array('fvTitle' => $filename), $fsl);
         $fv->refreshAttributes($this->rescanThumbnailsOnImport);
     } else {
         // We get a new version to modify
         $fv = $fr->getVersionToModify(true);
         $fv->updateFile($sanitizedFilename, $prefix);
         $fv->refreshAttributes($this->rescanThumbnailsOnImport);
     }
     return $fv;
 }
Пример #4
0
 /**
  * @return \Concrete\Core\File\StorageLocation\StorageLocation
  */
 public function getFileStorageLocationObject()
 {
     return parent::getFileStorageLocationObject();
 }