Exemplo n.º 1
0
 function saveFileAs($target, $chmod = 0644, &$substitutions = array())
 {
     if (!$this->hasFile()) {
         return false;
     }
     $info = pathinfo($this->_value['name']);
     $replacements = array('name' => $info['filename'], 'ext' => $info['extension']);
     $target = PathHelper::parse($target, $replacements, $substitutions);
     $dirname = dirname($target);
     if (!file_exists($dirname)) {
         $old = umask(0);
         mkdir($dirname, 0777, true);
         umask($old);
     }
     if (!$this->_saved_to) {
         $success = @move_uploaded_file($this->_value["tmp_name"], $target);
         $this->_saved_to = $target;
     } else {
         $success = @copy($this->_saved_to, $target);
     }
     if (!$success) {
         return false;
     }
     @chmod($target, $chmod);
     return $target;
 }
Exemplo n.º 2
0
 protected function getFilesToDelete($rows, $delete_files = array())
 {
     $file_columns = $this->getColumnsByType(array('filename', 'image'));
     foreach ($rows as $row) {
         foreach ($file_columns as $column) {
             $target_dirs = $column->getTargetDirs();
             foreach ($target_dirs as $dir) {
                 $delete_files[] = PathHelper::parse($dir . DS . $row[$column->getName()]);
             }
             $delete_files[] = PathHelper::parse(PathHelper::join(array('{public}/' . DEFAULT_MODULE . '/admin', $this->name . '/' . $column->getName()))) . DS . $row[$column->getName()];
             $delete_files[] = PathHelper::parse(PathHelper::join(array('{public}/' . DEFAULT_MODULE . '/admin', $this->name . '/' . $column->getName() . '/small'))) . DS . $row[$column->getName()];
         }
     }
     return $delete_files;
 }
 /**
  *
  * @example
  * 
  * $this->createThumbs(
  * 		array('best',	'[programa]/{random[10]}_{width}x{height}.{ext}'	300, 500),
  *		array('width',	'[programa]/{random[10]}_width.{ext}',	110),
  * 		array('square', '[programa]/{random[10]}_square.{ext}',	80),
  * 		array('crop', 	'[programa]/{random[10]}_crop_{width}x{height}.{ext}',	300, 500),
  * 		array('height',	'[programa]/{random[10]}_height.{ext}',	180),
  * 		array('filled', '[programa]/{random[10]}_filled.{ext}',	365),
  *		array('original','[programa]/{random[10]}.{ext}')
  * 	);
  *
  * @return array
  */
 function createThumbs()
 {
     if (!$this->hasFile()) {
         return false;
     }
     $thumbs = func_get_args();
     #No thumbs specified
     if (!count($thumbs)) {
         return false;
     }
     #Save temporarily the original image in the tmp directory
     $path = APPD_TMP . DS . '{random}.{ext}';
     $source = $this->saveFileAs($path);
     if (!$source) {
         trigger_error("Could not create temporary thumbnail.", E_USER_WARNING);
         return false;
     }
     Loader::includeLibrary('phaxsithumb/PhaxsiThumb.php');
     $fk_thumb = new PhaxsiThumb($source);
     if ($fk_thumb->isError()) {
         @unlink($source);
         return false;
     }
     #Generate filenames if needed. $names will be returned.
     $names = array();
     for ($i = 0; $i < count($thumbs); $i++) {
         $info = pathinfo($this->_value['name']);
         $replacements = array('size' => isset($thumbs[$i][2]) ? $thumbs[$i][2] : '', 'width' => isset($thumbs[$i][2]) ? $thumbs[$i][2] : '', 'height' => isset($thumbs[$i][3]) ? $thumbs[$i][3] : '', 'name' => $info['filename'], 'ext' => $info['extension']);
         $thumbs[$i][1] = PathHelper::replaceUploadsDir($thumbs[$i][1]);
         $thumbs[$i][1] = PathHelper::parse($thumbs[$i][1], $replacements);
         $dir = dirname($thumbs[$i][1]);
         if (!file_exists($dir)) {
             $old = umask(0);
             mkdir($dir, 0777, true);
             umask($old);
         }
         $names[$i] = $thumbs[$i][1];
     }
     $success = call_user_func_array(array(&$fk_thumb, 'batchCreateThumbs'), $thumbs);
     @unlink($source);
     if (!$success) {
         return false;
     }
     return $names;
 }