Example #1
0
 function execute($temp_name, $allow_existing_file = false)
 {
     if ($this->_autoRename) {
         $this->_cleanFilename();
         $this->_path_target = $this->_findSafeFilename();
     }
     if (!isset($this->_whitelist[$this->_file_extension])) {
         die('File extension is not permitted.');
     }
     $finfo = new finfo(FILEINFO_MIME);
     $mime_type = $finfo->file($temp_name);
     $mime_type = explode(';', $mime_type);
     $mime_type = $mime_type[0];
     if ($mime_type != $this->_whitelist[$this->_file_extension]) {
         die('File type/extension combination not permitted for security reasons.');
     }
     if (is_uploaded_file($temp_name)) {
         if (!move_uploaded_file($temp_name, $this->_path_target)) {
             return false;
         }
     } elseif ($allow_existing_file) {
         if (!rename($temp_name, $this->_path_target)) {
             return false;
         }
     } else {
         return false;
     }
     chmod($this->_path_target, 0755);
     AMP_s3_save($this->_path_target);
     AMP_lookup_clear_cached('downloads');
     return true;
 }
Example #2
0
 function makeVersion($version_class, $save = true)
 {
     $target_path = $this->_paths[$version_class];
     $source = $this->_getVersionSource($version_class);
     $new_height = $source->height * ($this->_widths[$version_class] / $source->width);
     $new_resource =& $source->resize($this->_widths[$version_class], $new_height);
     if (!$save) {
         return $new_resource;
     }
     if (!$source->write_image_resource($new_resource, $target_path)) {
         $this->addError(sprintf(AMP_TEXT_ERROR_FILE_WRITE_FAILED, $target_path));
         return false;
     }
     $this->setFilePermission($target_path);
     AMP_s3_save($target_path);
 }
Example #3
0
 function execute($temp_name, $allow_existing_file = false)
 {
     if ($this->_autoRename) {
         $this->_cleanFilename();
         $this->_path_target = $this->_findSafeFilename();
     }
     if (is_uploaded_file($temp_name)) {
         if (!move_uploaded_file($temp_name, $this->_path_target)) {
             return false;
         }
     } elseif ($allow_existing_file) {
         if (!rename($temp_name, $this->_path_target)) {
             return false;
         }
     } else {
         return false;
     }
     chmod($this->_path_target, 0755);
     AMP_s3_save($this->_path_target);
     AMP_lookup_clear_cached('downloads');
     return true;
 }
Example #4
0
 function write_image_resource(&$image_resource, $path = null, $direct = false)
 {
     if (!(isset($path) || $this->getName() || $direct)) {
         trigger_error('No path specified for writing image.');
         return false;
     }
     if (!isset($path)) {
         $path = $this->getPath();
     }
     if (!is_writeable($path)) {
         $file_part = basename($path);
         $path_only = $file_part ? str_replace(DIRECTORY_SEPARATOR . $file_part, '', $path) : $path;
         if (!is_writeable($path_only)) {
             trigger_error(sprintf(AMP_TEXT_ERROR_FILE_WRITE_FAILED, $path_only));
         }
     }
     if (!($write_method = $this->_get_action_method('write'))) {
         return false;
     }
     if ($direct) {
         return $write_method($image_resource);
     }
     $result = $write_method($image_resource, $path);
     if ($result) {
         AMP_s3_save($path);
     }
     return $result;
 }