/**
  * Physically creates asset
  *
  * @param string  $assetPath path to the asset original file
  * @param boolean $move      do move or just copy ?
  * @param boolean $move      check duplicate?
  */
 public function create($assetPath, $move = true, $checkDuplicate = true)
 {
     if (!is_file($assetPath)) {
         throw new sfAssetException('Asset "%asset%" not found', array('%asset%' => $assetPath));
     }
     // calculate asset properties
     if (!$this->getFilename()) {
         list(, $filename) = sfAssetsLibraryTools::splitPath($assetPath);
         $this->setFilename($filename);
     }
     // check folder
     if (!$this->getFolder()->existsPhysical()) {
         $this->getFolder()->create();
     } elseif ($checkDuplicate && sfAssetTable::getInstance()->exists($this->getFolder()->getId(), $this->filename)) {
         $this->setFilename(time() . $this->getFilename());
     }
     $this->setFilesize((int) (filesize($assetPath) / 1024));
     $this->autoSetType();
     if (sfConfig::get('app_sfAssetsLibrary_check_type', false) && !in_array($this->getType(), sfConfig::get('app_sfAssetsLibrary_types', array('image', 'txt', 'archive', 'pdf', 'xls', 'doc', 'ppt')))) {
         throw new sfAssetException('Filetype "%type%" not allowed', array('%type%' => $this->getType()));
     }
     $ok = $move ? @rename($assetPath, $this->getFullPath()) : @copy($assetPath, $this->getFullPath());
     if (!$ok) {
         //      throw new sfAssetException(sprintf('A problem occurred during while saving "%s", "%s"', $this->getFullPath(), $this->filename));
         throw new sfAssetException('A problem occurred during while saving "%file%"', array('%file%' => $this->getFullPath()));
     }
     if ($this->supportsThumbnails()) {
         sfAssetsLibraryTools::createThumbnails($this->getFolderPath(), $this->getFilename(), $this->isPdf());
     }
 }
Пример #2
0
 /**
  * Physically creates asset
  *
  * @param string $asset_path path to the asset original file
  * @param bool $move do move or just copy ?
  */
 public function create($asset_path, $move = true, $checkDuplicate = true)
 {
     if (!is_file($asset_path)) {
         throw new sfAssetException('Asset "%asset%" not found', array('%asset%' => $asset_path));
     }
     // calculate asset properties
     if (!$this->getFilename()) {
         list(, $filename) = sfAssetsLibraryTools::splitPath($asset_path);
         $this->setFilename($filename);
     }
     // check folder
     if (!$this->getsfAssetFolder()->exists()) {
         $this->getsfAssetFolder()->create();
     } else {
         // check if a file with this name already exists
         if ($checkDuplicate && sfAssetPeer::exists($this->getsfAssetFolder()->getId(), $this->getFilename())) {
             $this->setFilename(time() . $this->getFilename());
         }
     }
     $this->setFilesize((int) filesize($asset_path) / 1024);
     $this->autoSetType();
     if (sfConfig::get('app_sfAssetsLibrary_check_type', false) && !in_array($this->getType(), sfConfig::get('app_sfAssetsLibrary_types', array('image', 'txt', 'archive', 'pdf', 'xls', 'doc', 'ppt')))) {
         throw new sfAssetException('Filetype "%type%" not allowed', array('%type%' => $this->getType()));
     }
     if ($move) {
         rename($asset_path, $this->getFullPath());
     } else {
         copy($asset_path, $this->getFullPath());
     }
     if ($this->supportsThumbnails()) {
         sfAssetsLibraryTools::createThumbnails($this->getFolderPath(), $this->getFilename());
     }
 }