Пример #1
0
 /**
  * Perform the simple HTML upload for frontend forms.
  *
  * @param $file_info
  * @param $filedir_id
  * @return mixed
  */
 private function _simple_html_upload($file_info, $filedir_id)
 {
     $filename = $file_info['name'];
     try {
         $source = $this->EE->assets_lib->instantiate_source_type((object) array('source_type' => 'ee', 'filedir_id' => $filedir_id));
         $filedir = $source->settings();
         if ($filedir->max_size && filesize($file_info['tmp_name']) > $filedir->max_size) {
             return FALSE;
         }
         $filename = preg_replace('/[^a-z0-9_\\-\\.]/i', '_', $filename);
         $file_parts = explode('.', $filename);
         $ext = array_pop($file_parts);
         $file_base = join(".", $file_parts);
         $filename = $file_base . '.' . $ext;
         $target = $filedir->server_path . $filename;
         $i = 0;
         while (file_exists($target)) {
             if (is_numeric($i) && $i < 50) {
                 $i++;
             } else {
                 $i = uniqid('', TRUE);
             }
             $filename = $file_base . '_' . $i . '.' . $ext;
             $target = $filedir->server_path . $filename;
         }
         move_uploaded_file($file_info['tmp_name'], $target);
         $file_id = $this->EE->assets_lib->register_ee_file($filedir->id, $filename);
         if ($file_id) {
             Assets_helper::create_ee_thumbnails($target, $filedir->id);
             return $file_id;
         }
     } catch (Exception $exception) {
         // Skip this.
     }
 }
Пример #2
0
 /**
  * Creates thumbnails for uploaded image according to image manipulations specified
  *
  * @param string $image_path
  * @param int $upload_folder_id
  * @return bool
  */
 private function _create_thumbnails($image_path, $upload_folder_id)
 {
     $this->EE->load->library('filemanager');
     $this->EE->load->helper('file_helper');
     $filedir = $this->get_filedir($upload_folder_id);
     $this->EE->filemanager->max_hw_check($image_path, (array) $filedir);
     $site_id = $filedir->site_id;
     $this->EE->config->site_prefs('', $site_id);
     $image_path = Assets_helper::normalize_path($image_path);
     return Assets_helper::create_ee_thumbnails($image_path, $upload_folder_id);
 }