コード例 #1
1
ファイル: uploader.php プロジェクト: rabbitXIII/FFAReplays
 public function upload()
 {
     $this->load->library('replay');
     error_reporting(E_ALL | E_STRICT);
     $this->load->helper("upload.class");
     $upload_handler = new UploadHandler();
     header('Pragma: no-cache');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Content-Disposition: inline; filename="files.json"');
     header('X-Content-Type-Options: nosniff');
     header('Access-Control-Allow-Origin: *');
     header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
     header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
     switch ($_SERVER['REQUEST_METHOD']) {
         case 'OPTIONS':
             break;
         case 'HEAD':
         case 'GET':
             $upload_handler->get();
             break;
         case 'POST':
             if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
                 $upload_handler->delete();
             } else {
                 $upload_handler->post();
             }
             break;
         case 'DELETE':
             $upload_handler->delete();
             break;
         default:
             header('HTTP/1.1 405 Method Not Allowed');
     }
 }
コード例 #2
1
 /**
  * Transform trimmed filename to filesystem-friendly string
  *
  * @param $file_path
  * @param $name
  * @param $size
  * @param $type
  * @param $error
  * @param $index
  * @param $content_range
  *
  * @return string
  */
 protected function trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range)
 {
     $trimmedName = parent::trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range);
     $fileNameParts = pathinfo($trimmedName);
     $slugOfName = $this->slug($fileNameParts['filename']);
     $resultFileName = $slugOfName . '.' . $fileNameParts['extension'];
     $this->setUploadedFileName($resultFileName);
     return $resultFileName;
 }
コード例 #3
0
ファイル: uploadfile.php プロジェクト: ngxuanmui/hp3
 public function handle()
 {
     // required upload handler helper
     require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helpers' . DS . 'uploadhandler.php';
     $userId = JFactory::getUser()->id;
     $session = JFactory::getSession();
     $sessionId = $session->getId();
     // make dir
     $tmpImagesDir = JPATH_ROOT . DS . 'tmp' . DS . $userId . DS . $sessionId . DS;
     $tmpUrl = 'tmp/' . $userId . '/' . $sessionId . '/';
     // unlink before create
     @unlink($tmpImagesDir);
     // create folder
     @mkdir($tmpImagesDir, 0777, true);
     $uploadOptions = array('upload_dir' => $tmpImagesDir, 'upload_url' => $tmpUrl, 'script_url' => JRoute::_('index.php?option=com_ntrip&task=uploadfile.handle', false));
     $uploadHandler = new UploadHandler($uploadOptions, false);
     //	$session->set('files', null);
     $files = $session->get('files', array());
     if ($session->get('request_method') == 'delete') {
         $fileDelete = $uploadHandler->delete(false);
         // search file
         $key = array_search($fileDelete, $files);
         // unset in $files
         unset($files[$key]);
         $session->set('files', $files);
         $session->set('request_method', null);
         exit;
     }
     if ($_POST) {
         $file = $uploadHandler->post();
         $files[] = $file;
         $session->set('files', $files);
     }
     exit;
 }
コード例 #4
0
 public function upload($config = 'default')
 {
     if (!$this->request->is(array('post', 'put', 'delete'))) {
         die('Method not allowed');
     }
     App::import('Vendor', 'BlueUpload.UploadHandler', array('file' => 'UploadHandler.php'));
     $options = Configure::read("BlueUpload.options.{$config}");
     $upload_handler = new UploadHandler($options, $initialize = false);
     if ($this->request->is(array('post', 'put'))) {
         $content = $upload_handler->post($print_response = false);
         // save into uploads table
         foreach ($content['files'] as &$file) {
             if (!isset($file->error)) {
                 $upload = array('name' => $file->name, 'size' => $file->size, 'type' => $file->type, 'url' => $file->url, 'dir' => $options['upload_dir'], 'deleteUrl' => $file->deleteUrl, 'deleteType' => $file->deleteType);
                 // 'thumbnailUrl' => $file->thumbnailUrl,
                 // 'previewUrl'   => $file->previewUrl,
                 //  ... etc
                 if (isset($options['image_versions'])) {
                     foreach ($options['image_versions'] as $version_name => $version) {
                         if (!empty($version_name)) {
                             $upload[$version_name . 'Url'] = $file->{$version_name . 'Url'};
                         }
                     }
                 }
                 // invoke a custom event so app can mangle the data
                 $event = new CakeEvent('Model.BlueUpload.beforeSave', $this, array('upload' => $upload));
                 $this->Upload->getEventManager()->dispatch($event);
                 if ($event->isStopped()) {
                     continue;
                 }
                 // pickup mangled data
                 if (!empty($event->result['upload'])) {
                     $upload = $event->result['upload'];
                 }
                 $this->Upload->create();
                 $this->Upload->save($upload);
                 $file->id = $this->Upload->getLastInsertID();
                 unset($file->deleteUrl);
                 unset($file->deleteType);
                 // account for apps installed in subdir of webroot
                 $file->url = Router::url($file->url);
                 if (isset($file->thumbnailUrl)) {
                     $file->thumbnailUrl = Router::url($file->thumbnailUrl);
                 }
             }
         }
     } else {
         if ($this->request->is(array('delete'))) {
             $content = $upload_handler->delete($print_response = false);
             // delete from uploads table
             foreach ($content['files'] as &$file) {
             }
         }
     }
     $json = json_encode($content);
     $upload_handler->head();
     echo $json;
     $this->autoRender = false;
 }
コード例 #5
0
 public function handleSave()
 {
     require_once __DIR__ . "/../../vendor/fineuploader/Uploader/handler.php";
     $uploader = new \UploadHandler();
     $uploader->allowedExtensions = array("jpeg", "jpg", "png", "gif");
     $result = $uploader->handleUpload(__DIR__ . '/../../www/images/uploaded');
     $this->sendResponse(new \Nette\Application\Responses\JsonResponse($result));
 }
 public function upload($options = null)
 {
     if (!isset($options['print_response'])) {
         $options['print_response'] = false;
     }
     $upload = new \UploadHandler($options);
     return $upload->get_response();
 }
コード例 #7
0
ファイル: ProcessFiles.php プロジェクト: Oshan07/test-project
function getLocalFileDetails()
{
    // Initializing normal file upload handler
    $upload_handler = new UploadHandler();
    $fileDetails = $upload_handler->post(false);
    $fileDetails["uploadDir"] = $_POST['folderName'];
    return $fileDetails;
}
コード例 #8
0
 /**
  * Override the default method to handle the specific things of the download module and
  * update the database after file was successful uploaded.
  * This method has the same parameters as the default.
  * @param  $uploaded_file
  * @param  $name
  * @param  $size
  * @param  $type
  * @param  $error
  * @param  $index
  * @param  $content_range
  * @return stdClass
  */
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     global $gPreferences, $gL10n, $gDb, $getId, $gCurrentOrganization, $gCurrentUser;
     $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
     if (!isset($file->error)) {
         try {
             // check filesize against module settings
             if ($file->size > $gPreferences['max_file_upload_size'] * 1024 * 1024) {
                 throw new AdmException('DOW_FILE_TO_LARGE', $gPreferences['max_file_upload_size']);
             }
             // check filename and throw exception if something is wrong
             admStrIsValidFileName($file->name, true);
             // get recordset of current folder from database and throw exception if necessary
             $targetFolder = new TableFolder($gDb);
             $targetFolder->getFolderForDownload($getId);
             // now add new file to database
             $newFile = new TableFile($gDb);
             $newFile->setValue('fil_fol_id', $targetFolder->getValue('fol_id'));
             $newFile->setValue('fil_name', $file->name);
             $newFile->setValue('fil_locked', $targetFolder->getValue('fol_locked'));
             $newFile->setValue('fil_counter', '0');
             $newFile->save();
             // Benachrichtigungs-Email für neue Einträge
             $message = $gL10n->get('DOW_EMAIL_NOTIFICATION_MESSAGE', $gCurrentOrganization->getValue('org_longname'), $file->name, $gCurrentUser->getValue('FIRST_NAME') . ' ' . $gCurrentUser->getValue('LAST_NAME'), date($gPreferences['system_date'], time()));
             $notification = new Email();
             $notification->adminNotfication($gL10n->get('DOW_EMAIL_NOTIFICATION_TITLE'), $message, $gCurrentUser->getValue('FIRST_NAME') . ' ' . $gCurrentUser->getValue('LAST_NAME'), $gCurrentUser->getValue('EMAIL'));
         } catch (AdmException $e) {
             $file->error = $e->getText();
             unlink($this->options['upload_dir'] . $file->name);
             return $file;
         }
     }
     return $file;
 }
コード例 #9
0
ファイル: lhfileupload.php プロジェクト: sirromas/medical
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     $matches = array();
     if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $type, $matches)) {
         $name = $uploadFileName = 'clipboard.' . $matches[1];
     } else {
         $uploadFileName = $name;
     }
     if (!preg_match($this->options['accept_file_types_lhc'], $uploadFileName)) {
         $file->error = $this->get_error_message('accept_file_types');
         return false;
     }
     $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
     if (empty($file->error)) {
         $fileUpload = new erLhcoreClassModelChatFile();
         $fileUpload->size = $file->size;
         $fileUpload->type = $file->type;
         $fileUpload->name = $file->name;
         $fileUpload->date = time();
         $fileUpload->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0;
         $fileUpload->upload_name = $name;
         $fileUpload->file_path = $this->options['upload_dir'];
         if (isset($this->options['chat']) && $this->options['chat'] instanceof erLhcoreClassModelChat) {
             $fileUpload->chat_id = $this->options['chat']->id;
         } elseif (isset($this->options['online_user']) && $this->options['online_user'] instanceof erLhcoreClassModelChatOnlineUser) {
             $fileUpload->online_user_id = $this->options['online_user']->id;
         }
         $matches = array();
         if (strpos($name, '.') === false && preg_match('/^image\\/(gif|jpe?g|png)/', $fileUpload->type, $matches)) {
             $fileUpload->extension = $matches[1];
         } else {
             $partsFile = explode('.', $fileUpload->upload_name);
             $fileUpload->extension = end($partsFile);
         }
         $fileUpload->saveThis();
         $file->id = $fileUpload->id;
         if (isset($this->options['chat']) && $this->options['chat'] instanceof erLhcoreClassModelChat) {
             // Chat assign
             $chat = $this->options['chat'];
             // Format message
             $msg = new erLhcoreClassModelmsg();
             $msg->msg = '[file=' . $file->id . '_' . md5($fileUpload->name . '_' . $fileUpload->chat_id) . ']';
             $msg->chat_id = $chat->id;
             $msg->user_id = isset($this->options['user_id']) ? $this->options['user_id'] : 0;
             if ($msg->user_id > 0 && isset($this->options['name_support'])) {
                 $msg->name_support = (string) $this->options['name_support'];
             }
             $chat->last_user_msg_time = $msg->time = time();
             erLhcoreClassChat::getSession()->save($msg);
             // Set last message ID
             if ($chat->last_msg_id < $msg->id) {
                 $chat->last_msg_id = $msg->id;
             }
             $chat->has_unread_messages = 1;
             $chat->updateThis();
         }
         $this->uploadedFile = $fileUpload;
     }
     return $file;
 }
コード例 #10
0
 public function __construct($options = null, $initialize = true, $error_messages = null)
 {
     $this->options = ['csrf_token' => ['name' => '_token', 'value' => csrf_token()], 'script_url' => \URL::current(), 'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')) . '/files/', 'upload_url' => $this->get_full_url() . '/files/'];
     if ($options) {
         $this->options = $options + $this->options;
     }
     parent::__construct($this->options, $initialize, $error_messages);
 }
コード例 #11
0
 public function processupload()
 {
     header('Access-Control-Allow-Origin: *');
     //$this->load->library('uploadhandler');
     $options = array('upload_dir' => './uploads/profile/', 'upload_url' => base_url() . '/uploads/profile/', 'accept_file_types' => '/\\.(gif|jpeg|jpg|png)$/i');
     //$this->load->library('uploadhandler',$options);
     UploadHandler::model($options);
 }
コード例 #12
0
ファイル: ProjectGlobal.php プロジェクト: awwthentic1234/hey
 public static function init()
 {
     Constants::$host = self::$host;
     Constants::$pass = self::$pass;
     Constants::$user = self::$user;
     Constants::$database = self::$database;
     UploadHandler::$projectFilesPath = ProjectGlobal::$projectFilesPath;
     UploadHandler::$rootFilesPath = "/upload/generated_files/";
 }
コード例 #13
0
 function __construct($options = null)
 {
     //izveido direktoriju
     $options['upload_dir'] = self::getUploadDirPath($options['model_name']);
     $options['accept_file_types'] = Yii::app()->getModule('d1files')->accept_file_types;
     //lai netaisa thumb...
     $options['image_versions'] = array();
     parent::__construct($options, TRUE);
 }
コード例 #14
0
 protected function set_file_delete_properties($file)
 {
     parent::set_file_delete_properties($file);
     if ($this->delete_url != null) {
         if (substr($this->delete_url, -1) != '/') {
             $this->delete_url .= '/';
         }
         $file->delete_url = $this->delete_url . rawurlencode($file->name);
     }
 }
コード例 #15
0
ファイル: ewupload10.php プロジェクト: evinw/project_yess
 public function post($print_response = true)
 {
     $ar = parent::post(FALSE);
     if (array_key_exists($this->options["param_name"], $ar)) {
         $ar["files"] = $ar[$this->options["param_name"]];
         // Set key as "files" for jquery.fileupload-ui.js
         unset($ar[$this->options["param_name"]]);
     }
     return $this->generate_response($ar, $print_response);
 }
コード例 #16
0
ファイル: ProjectGlobal.php プロジェクト: awwthentic1234/hey
 public static function init()
 {
     Constants::$host = self::$host;
     Constants::$pass = self::$pass;
     Constants::$user = self::$user;
     Constants::$database = self::$database;
     Account_v0::$confirmation_url = Import::getImportPath(true) . "confirmation.php";
     Account_v0::$forgot_url = Import::getImportPath(true) . "forgot.php";
     UploadHandler::$projectFilesPath = ProjectGlobal::$projectFilesPath;
     UploadHandler::$rootFilesPath = "upload/generated_files/";
 }
コード例 #17
0
 public function delete($print_response = true)
 {
     $response = parent::delete(false);
     foreach ($response as $name => $deleted) {
         if ($deleted) {
             $sql = 'DELETE FROM `' . $this->options['db_table'] . '` WHERE `name`=?';
             $query = $this->db->prepare($sql);
             $query->bind_param('s', $name);
             $query->execute();
         }
     }
     return $this->generate_response($response, $print_response);
 }
コード例 #18
0
ファイル: ProjectGlobal.php プロジェクト: awwthentic1234/hey
 public static function init()
 {
     Compiler::init(array("css" => "min_single", "js" => "min_single", "getServices" => array("except" => Import::getImportPath() . "service.php"), "global" => array("copy" => array(Import::$uber_src_path . "service.php", Import::getImportPath() . "index.php"), "getImages" => true, "code" => array("tmpl" => array("replace" => array("replaceSrc" => false, "\${images}" => Import::$uber_src_path . "/global/images/")))), "compile" => array(array("id" => "min_single", "minify" => true, "copy" => array(), "code" => array("css" => array("singleFile" => true, "path" => "global/css/"), "js" => array("singleFile" => true, "path" => "global/js/"))), array("id" => "min_multi", "minify" => true, "code" => array("css" => array("singleFile" => false, "path" => "global/css/"), "js" => array("singleFile" => false, "path" => "global/js/"))), array("id" => "unmin", "code" => array("css" => array("singleFile" => false, "path" => "global/css/"), "js" => array("singleFile" => false, "path" => "global/js/"))), array("id" => "unmin_raw", "raw" => true))));
     //------------------------------------------------
     GlobalMas::$host = self::$host;
     GlobalMas::$pass = self::$pass;
     GlobalMas::$user = self::$user;
     GlobalMas::$database = self::$database;
     UploadHandler::$projectFilesPath = ProjectGlobal::$projectFilesPath;
     //UploadHandler::$rootFilesPath = "/upload/generated_files/";
     self::$filesLocalPath = $_SERVER['DOCUMENT_ROOT'] . "/" . UploadHandler::$rootFilesPath . self::$projectFilesPath;
     self::$filesPath = GenFun::get_full_url(self::$filesLocalPath);
 }
コード例 #19
0
 public function generate_response($content, $print_response = true)
 {
     if ($print_response && !empty($content['files'])) {
         foreach ($content['files'] as $key => $content_image_data) {
             if (!empty($this->options['selected_data'][$content_image_data->name])) {
                 foreach (get_object_vars($this->options['selected_data'][$content_image_data->name]) as $var => $data) {
                     $content['files'][$key]->{$var} = $data;
                 }
             }
         }
         usort($content['files'], ['self', 'order_items']);
     }
     return parent::generate_response($content, $print_response);
 }
コード例 #20
0
ファイル: index.php プロジェクト: schutterskwartier/flot
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     try {
         $this->flot = new Flot();
         $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
         if (empty($file->error)) {
             $o_ImageProcessor = new ImageProcessor(S_BASE_PATH, S_BASE_EXTENSION . $this->flot->datastore->settings->upload_dir, $file->name);
             $o_ImageProcessor->process_and_tag_to_datastore();
         } else {
             echo $file->error;
         }
         return $file;
     } catch (Exception $e) {
         echo $e;
     }
 }
コード例 #21
0
ファイル: upload.php プロジェクト: Hawkart/megatv
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     $file = parent::handle_file_upload($uploaded_file, $name, $size, $type, $error, $index, $content_range);
     if (empty($file->error)) {
         global $USER;
         $uid = $USER->GetID();
         $rsUser = CUser::GetByID($uid);
         $arUser = $rsUser->Fetch();
         $arFile = CFile::MakeFileArray($_SERVER['DOCUMENT_ROOT'] . "/upload/avatar/thumbnail/" . $file->name);
         $arFile['del'] = "Y";
         $arFile['old_file'] = $arUser['PERSONAL_PHOTO'];
         $arFile["MODULE_ID"] = "main";
         $fields['PERSONAL_PHOTO'] = $arFile;
         $cuser = new CUser();
         $cuser->Update($uid, $fields);
     }
     return $file;
 }
コード例 #22
0
/*
 * jQuery File Upload Plugin PHP Example 5.7
 * https://github.com/blueimp/jQuery-File-Upload
 *
 * Copyright 2010, Sebastian Tschan
 * https://blueimp.net
 *
 * Licensed under the MIT license:
 * http://www.opensource.org/licenses/MIT
 */
error_reporting(E_ALL | E_STRICT);
require 'upload.class.php';
require_once "../../includes/initialize.php";
global $session;
$group = Group::get_by_id($session->user_group_id);
$upload_handler = new UploadHandler($group, "questions");
header('Pragma: no-cache');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Content-Disposition: inline; filename="files.json"');
header('X-Content-Type-Options: nosniff');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
switch ($_SERVER['REQUEST_METHOD']) {
    case 'OPTIONS':
        break;
    case 'HEAD':
    case 'GET':
        $upload_handler->get();
        break;
    case 'POST':
コード例 #23
0
ファイル: file-gator.php プロジェクト: aimtux/kiddiefile
 /**
  *
  * upload files with ajax
  */
 public function ajaxUpload()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         die;
     }
     require_once gatorconf::get('base_path') . "/include/blueimp/server/php/upload.class.php";
     $upload_handler = new UploadHandler();
     header('Pragma: no-cache');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Content-Disposition: inline; filename="files.json"');
     header('X-Content-Type-Options: nosniff');
     header('Access-Control-Allow-Origin: *');
     header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
     header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
     $filename = '?';
     if (isset($_FILES['files']['name'])) {
         $filename = $this->filterInput(implode(" ", $_FILES['files']['name']));
         if (in_array($filename, gatorconf::get('restricted_files'))) {
             die;
         }
     }
     gator::writeLog('upload file ' . $filename);
     $upload_handler->post();
     die;
 }
コード例 #24
0
ファイル: Grocery_CRUD.php プロジェクト: qwords/evote
 protected function upload_file($state_info)
 {
     if (isset($this->upload_fields[$state_info->field_name])) {
         if ($this->callback_upload === null) {
             if ($this->callback_before_upload !== null) {
                 $callback_before_upload_response = call_user_func($this->callback_before_upload, $_FILES, $this->upload_fields[$state_info->field_name]);
                 if ($callback_before_upload_response === false) {
                     return false;
                 } elseif (is_string($callback_before_upload_response)) {
                     return $callback_before_upload_response;
                 }
             }
             $upload_info = $this->upload_fields[$state_info->field_name];
             header('Pragma: no-cache');
             header('Cache-Control: private, no-cache');
             header('Content-Disposition: inline; filename="files.json"');
             header('X-Content-Type-Options: nosniff');
             header('Access-Control-Allow-Origin: *');
             header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
             header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
             $allowed_files = $this->config->file_upload_allow_file_types;
             $reg_exp = '';
             if (!empty($upload_info->allowed_file_types)) {
                 $reg_exp = '/(\\.|\\/)(' . $upload_info->allowed_file_types . ')$/i';
             } else {
                 $reg_exp = '/(\\.|\\/)(' . $allowed_files . ')$/i';
             }
             $max_file_size_ui = $this->config->file_upload_max_file_size;
             $max_file_size_bytes = $this->_convert_bytes_ui_to_bytes($max_file_size_ui);
             $options = array('upload_dir' => $upload_info->upload_path . '/', 'param_name' => $this->_unique_field_name($state_info->field_name), 'upload_url' => base_url() . $upload_info->upload_path . '/', 'accept_file_types' => $reg_exp, 'max_file_size' => $max_file_size_bytes);
             $upload_handler = new UploadHandler($options);
             $upload_handler->default_config_path = $this->default_config_path;
             $uploader_response = $upload_handler->post();
             if (is_array($uploader_response)) {
                 foreach ($uploader_response as &$response) {
                     unset($response->delete_url);
                     unset($response->delete_type);
                 }
             }
             if ($this->callback_after_upload !== null) {
                 $callback_after_upload_response = call_user_func($this->callback_after_upload, $uploader_response, $this->upload_fields[$state_info->field_name], $_FILES);
                 if ($callback_after_upload_response === false) {
                     return false;
                 } elseif (is_string($callback_after_upload_response)) {
                     return $callback_after_upload_response;
                 } elseif (is_array($callback_after_upload_response)) {
                     $uploader_response = $callback_after_upload_response;
                 }
             }
             return $uploader_response;
         } else {
             $upload_response = call_user_func($this->callback_upload, $_FILES, $this->upload_fields[$state_info->field_name]);
             if ($upload_response === false) {
                 return false;
             } else {
                 return $upload_response;
             }
         }
     } else {
         return false;
     }
 }
コード例 #25
0
 public function processRequest()
 {
     // Ignore other requests except POST.
     if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_POST[PostFields::packageGuid])) {
         return;
     }
     if (UploadHandler::$_processed) {
         return;
     }
     UploadHandler::$_processed = true;
     if (array_key_exists('HTTP_X_PREPROCESS_REQUIRED', $_SERVER) && $_SERVER['HTTP_X_PREPROCESS_REQUIRED'] == 'true') {
         $files = $this->getRequestFiles($_POST);
     } else {
         $files =& $_FILES;
     }
     $uploadCache = new UploadCache($this->_cacheRoot);
     $uploadSession = new UploadSession($uploadCache, $_POST, $files, $_SERVER);
     if (!empty($this->_allFilesUploadedCallback)) {
         $uploadSession->setAllFilesUploadedCallback($this->_allFilesUploadedCallback);
     }
     if (!empty($this->_fileUploadedCallback)) {
         $uploadSession->setFileUploadedCallback($this->_fileUploadedCallback);
     }
     $uploadSession->processRequest();
     $this->removeExpiredSessions($uploadCache);
     // Flash requires non-empty response
     if (!headers_sent() && array_key_exists('HTTP_USER_AGENT', $_SERVER) && $_SERVER['HTTP_USER_AGENT'] === 'Shockwave Flash') {
         echo '0';
     }
 }
コード例 #26
0
ファイル: points.mod.php プロジェクト: noikiy/LINJU
 function UploadImage()
 {
     //$this->GotoLogin();
     $name = $_FILES['Filedata']['name'];
     $id = rand(10, 10000000);
     $rpath = 'images/building/face/' . face_path($id);
     $image_path = __WEB_ROOT . '/' . $rpath;
     $image_name = $id . '_o.jpg';
     $image_file = $rpath . $image_name;
     $image_file_s = $rpath . $id . '_s.jpg';
     $image_file_t = $rpath . $id . '_t.jpg';
     $image_file_p = $rpath . $id . '_p.jpg';
     $pic_field = 'Filedata';
     $UploadHandler = new UploadHandler($_FILES, $image_path, $pic_field, true, false);
     $UploadHandler->setMaxSize(2048);
     $UploadHandler->setNewName($image_name);
     $ret = $UploadHandler->doUpload();
     if (!$ret) {
         $rets = $UploadHandler->getError();
         $ret = $rets ? implode(" ", (array) $rets) : 'image upload is invalid';
         $r = array('error' => $ret, 'code' => -5);
         if ($r['code'] < 0 && $r['error']) {
             $this->_image_error($rets['error']);
         }
     }
     list($image_width, $image_height, $image_type, $image_attr) = getimagesize($image_file);
     if ($image_width >= 120 && $image_height <= 120) {
         resizeimage($image_file, $image_file_s, 120, 0, true);
     }
     if ($image_height >= 120 && $image_height <= 120) {
         resizeimage($image_file, $image_file_s, 0, 120, true);
     }
     if ($image_height > 120 && $image_width > 120 && $image_width > $image_height) {
         resizeimage($image_file, $image_file_s, 120, 0, true);
     }
     if ($image_height > 120 && $image_width > 120 && $image_width < $image_height) {
         resizeimage($image_file, $image_file_s, 0, 120, true);
     }
     resizeimage($image_file, $image_file_t, 600, 0, true);
     resizeimage($image_file, $image_file_p, 180, 180, false);
     $result = array();
     $result['status'] = "ok";
     $result['image'] = $image_file;
     echo json_encode($result);
 }
コード例 #27
0
ファイル: fileupload.php プロジェクト: stweil/glpi
 * @brief
 * @since version 0.85
 **/
if (!defined('GLPI_ROOT')) {
    define('GLPI_ROOT', dirname(__DIR__));
}
include_once GLPI_ROOT . "/inc/autoload.function.php";
include_once GLPI_ROOT . "/inc/db.function.php";
include_once GLPI_ROOT . "/config/config.php";
Session::checkLoginUser();
// Load Language file
Session::loadLanguage();
include_once GLPI_ROOT . '/lib/jqueryplugins/jquery-file-upload/server/php/UploadHandler.php';
$errors = array(1 => __('The uploaded file exceeds the upload_max_filesize directive in php.ini'), 2 => __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'), 3 => __('The uploaded file was only partially uploaded'), 4 => __('No file was uploaded'), 6 => __('Missing a temporary folder'), 7 => __('Failed to write file to disk'), 8 => __('A PHP extension stopped the file upload'), 'post_max_size' => __('The uploaded file exceeds the post_max_size directive in php.ini'), 'max_file_size' => __('File is too big'), 'min_file_size' => __('File is too small'), 'accept_file_types' => __('Filetype not allowed'), 'max_number_of_files' => __('Maximum number of files exceeded'), 'max_width' => __('Image exceeds maximum width'), 'min_width' => __('Image requires a minimum width'), 'max_height' => __('Image exceeds maximum height'), 'min_height' => __('Image requires a minimum height'));
$upload_dir = GLPI_TMP_DIR . '/';
$upload_handler = new UploadHandler(array('upload_dir' => $upload_dir, 'param_name' => $_GET['name'], 'orient_image' => false, 'image_versions' => array()), false, $errors);
$response = $upload_handler->post(false);
// clean compute display filesize
if (isset($response[$_GET['name']]) && is_array($response[$_GET['name']])) {
    foreach ($response[$_GET['name']] as $key => &$val) {
        if (Document::isValidDoc(addslashes($val->name))) {
            if (isset($val->name)) {
                $val->display = $val->name;
            }
            if (isset($val->size)) {
                $val->filesize = Toolbox::getSize($val->size);
                if (isset($_GET['showfilesize']) && $_GET['showfilesize']) {
                    $val->display = sprintf('%1$s %2$s', $val->display, $val->filesize);
                }
            }
        } else {
コード例 #28
0
ファイル: Tplate.php プロジェクト: nockout/tshpro
 public function processImage($template_id)
 {
     if (empty($template_id)) {
         return;
     }
     $this->CI->load->helper("upload");
     $path = UPLOAD_PATH . '../template/';
     $config['upload_dir'] = $path;
     $config['upload_dir'] = $config['upload_dir'];
     if (!is_dir($config['upload_dir'])) {
         //create the folder if it's not already exists
         mkdir($config['upload_dir'], 0755, TRUE);
     }
     $config['script_url'] = base_url() . $path;
     $config['upload_url'] = base_url() . $path;
     $upload_handler = new UploadHandler($config);
     header('Pragma: no-cache');
     header('Cache-Control: no-store, no-cache, must-revalidate');
     header('Content-Disposition: inline; filename="files.json"');
     header('X-Content-Type-Options: nosniff');
     header('Access-Control-Allow-Origin: *');
     header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
     header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
     switch ($_SERVER['REQUEST_METHOD']) {
         case 'OPTIONS':
             break;
         case 'HEAD':
         case 'GET':
             //$id_template= $template_id;
             $upload_dir = dirname($_SERVER['SCRIPT_FILENAME']) . $path;
             $url = base_url();
             $files = array();
             $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : "FRONT";
             //echo $type;
             if ($images = $this->CI->template_m->get_images($template_id, $type)) {
                 foreach ($images as $img) {
                     $returnpath = $path . $template_id . '_' . $img->id_image . $this->img_extension;
                     if (file_exists($returnpath)) {
                         $file = new stdClass();
                         $file->name = $template_id . '_' . $img->id_image . $this->img_extension;
                         $file->id_image = $img->id_image;
                         $file->url = $path . $template_id . '_' . $img->id_image . $this->img_extension;
                         $file->delete_url = site_url() . '/admin/template/img_upload' . '?id_image=' . rawurlencode($img->id_image) . '&&id_template=' . rawurlencode($template_id);
                         $file->delete_url .= '&&method=DELETE';
                         $file->deleteType = 'DELETE';
                         $file->url_default = site_url() . '/admin/template/set_default/' . $template_id . '/' . $img->id_image . '/' . $img->type;
                         $files[] = $file;
                     }
                 }
             }
             $obj = new stdClass();
             $obj->files = $files;
             ob_clean();
             print_r(json_encode($obj));
             ob_flush();
             break;
         case 'POST':
             if (isset($_REQUEST['method']) && $_REQUEST['method'] === 'DELETE') {
                 $upload_handler->delete();
             } else {
                 $id_template = $template_id;
                 $type = $this->CI->input->post('type') ? $this->CI->input->post('type') : "FRONT";
                 //parent::create($this->fields);
                 if (isset($_FILES['files'])) {
                     if ($timage = $this->CI->template_m->createimage($template_id, $type)) {
                         $new_file_path = $path . $id_template . "_" . $timage->id_image . $this->img_extension;
                         if (isset($_FILES['files']['tmp_name'][0])) {
                             $file_path = $_FILES['files']['tmp_name'][0];
                             if (file_exists($file_path)) {
                                 if ($file_path !== $new_file_path) {
                                     //	 @copy($file_path, $new_file_path);
                                     $config['image_library'] = 'gd2';
                                     $config['source_image'] = $file_path;
                                     $config['new_image'] = $new_file_path;
                                     $config['maintain_ratio'] = TRUE;
                                     $config['height'] = MAX_TEMPLATE_HEIGHT;
                                     $this->CI->load->library('image_lib');
                                     $resizer = new CI_Image_lib();
                                     $resizer->initialize($config);
                                     $resizer->resize();
                                 }
                             }
                         }
                     }
                     $files_return = array();
                     //     foreach ($images as $img) {
                     $file = new stdClass();
                     $file->name = $id_template . '_' . $timage->id_image . $this->img_extension;
                     $file->id_image = $timage->id_image;
                     $file->url = $path . $id_template . '_' . $timage->id_image . $this->img_extension;
                     $file->delete_url = $this->getFullUrl() . '/admin/template/img_upload' . '?id_image=' . rawurlencode($timage->id_image) . '&&id_template=' . rawurlencode($id_template);
                     $file->delete_url .= '&&method=DELETE';
                     $file->deleteType = 'DELETE';
                     $file->url_default = site_url() . '/admin/template/set_default/' . $id_template . '/' . $timage->id_image . '/' . $type;
                     $files_return[] = $file;
                     //  };
                     $object = new stdClass();
                     $object->files = $files_return;
                     ob_clean();
                     print_r(json_encode($object));
                     ob_flush();
                 }
             }
             break;
         case 'DELETE':
             if (!isset($_REQUEST['id_image'])) {
                 return;
             }
             if (!isset($_REQUEST['id_template'])) {
                 return;
             }
             $tid = $_REQUEST['id_template'];
             $image_id = $_REQUEST['id_image'];
             $this->CI->template_m->deleteimage($_REQUEST['id_image'], $_REQUEST['id_template']);
             $deltepath = $path . $tid . '_' . $image_id . $this->img_extension;
             //	echo $deltepath;die;
             if (file_exists($deltepath)) {
                 @unlink($deltepath);
             }
             ob_clean();
             ob_flush();
             //echo json_encode($this->tools->set_notification('N', 'notice', 'Delete successfull'));
             return;
             break;
         default:
             header('HTTP/1.1 405 Method Not Allowed');
     }
 }
コード例 #29
0
ファイル: uploader.php プロジェクト: DarneoStudio/bitrix
 public static function UploadFileHandler($callback, $Params)
 {
     self::HealFilesVars();
     self::InitUploaderHandler();
     self::$convCount = $Params['convCount'];
     self::$uploadCallbackFunc = $callback;
     self::$uploadCallbackParams = $Params;
     self::SetTmpPath($_REQUEST["PackageGuid"], $Params["pathToTmp"]);
     $uh = new UploadHandler();
     $uh->setUploadCacheDirectory($Params['pathToTmp']);
     $uh->setAllFilesUploadedCallback(array("CFlashUploader", "SaveAllUploadedFiles"));
     $uh->processRequest();
     // Kill unsecure vars from $_POST
     self::HealFilesVars(true);
 }
コード例 #30
-1
 public function upload()
 {
     $this->autoRender = false;
     App::uses('UploadHandler', 'Media.Vendor');
     $uploadHandler = new UploadHandler(array(), false);
     $files = $uploadHandler->post(false);
     $totalSize = 0;
     foreach ($files['files'] as $file) {
         $totalSize += (int) $file->size;
     }
     if ($totalSize <= 0) {
         throw new CakeException('Uploaded files is zero valued. Please try again', 500);
     }
     if (!$this->StorageLimit->checklimit($totalSize, $this->currUser['User']['id'])) {
         throw new CakeException('Cloud limit reached. Upgrade you subscription please', 403);
     }
     echo json_encode($files);
 }