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'); } }
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; }
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; }
function getLocalFileDetails() { // Initializing normal file upload handler $upload_handler = new UploadHandler(); $fileDetails = $upload_handler->post(false); $fileDetails["uploadDir"] = $_POST['folderName']; return $fileDetails; }
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); }
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': 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'); }
private function uploadHandler() { $options = array('url' => $this->createUrl("/files/", array('path' => Yii::app()->user->id . "/")), 'upload_dir' => Yii::getPathOfAlias(Yii::app()->params['filesAlias']) . DIRECTORY_SEPARATOR, 'upload_url' => $this->createUrl("/files/file"), 'script_url' => $this->createUrl("/files/uploadFile", array('path' => Yii::app()->user->id . "/")), 'field_name' => 'files', 'image_versions' => array()); // wrapper for jQuery-file-upload/upload.php $upload_handler = new UploadHandler($options); header('Pragma: no-cache'); header('Cache-Control: private, no-cache'); header('Content-Disposition: inline; filename="files.json"'); header('X-Content-Type-Options: nosniff'); ob_start(); switch ($_SERVER['REQUEST_METHOD']) { case 'HEAD': case 'GET': $upload_handler->get(); $contents = ob_get_contents(); break; case 'POST': // check if file exists $upload = $_FILES[$options['field_name']]; $tmp_name = $_FILES[$options['field_name']]['tmp_name']; if (is_array($tmp_name)) { foreach ($tmp_name as $index => $value) { //$model = files::model()->findByAttributes(array('path' => Yii::app()->user->id.DIRECTORY_SEPARATOR.$upload['name'][$index])); $model = new Files(); $attributes['path'] = Yii::app()->user->id . DIRECTORY_SEPARATOR . $upload['name'][$index]; $attributes['title'] = $upload['name'][$index]; // TODO: fix title unique check #var_dump($attributes['title']);exit; $model->attributes = $attributes; //var_dump($attributes);exit; $model->validate(); if ($model->hasErrors()) { #throw new CHttpException(500, 'File exists.'); $file = new stdClass(); $file->error = ""; foreach ($model->getErrors() as $error) { $file->error .= $error[0]; } $info[] = $file; echo CJSON::encode($info); exit; } } } $upload_handler->post(); $contents = ob_get_contents(); $result = CJSON::decode($contents); #var_dump($result);exit; $attr = $this->createMedia($result[0]['name'], Yii::app()->params['filesAlias']); $result[0]['url'] .= "/" . $attr['id']; $result[0]['delete_url'] .= "?id=" . $attr['id']; $contents = CJSON::encode($result); break; case 'DELETE': //$upload_handler->delete(); //$contents = ob_get_contents(); $result = $this->deleteMedia($_GET['id']); break; default: header('HTTP/1.0 405 Method Not Allowed'); $contents = ob_get_contents(); } ob_end_clean(); return $contents; }
private function uploadHandler() { #$script_dir = Yii::app()->basePath.'/data/p3media'; #$script_dir_url = Yii::app()->baseUrl; $options = array('url' => $this->createUrl("/p3media/p3Media/update", array('path' => Yii::app()->user->id . "/")), 'upload_dir' => $this->module->getDataPath() . DIRECTORY_SEPARATOR, 'upload_url' => $this->createUrl("/p3media/p3Media/update", array('preset' => 'raw', 'path' => Yii::app()->user->id . "/")), 'script_url' => $this->createUrl("/p3media/import/uploadFile", array('path' => Yii::app()->user->id . "/")), 'field_name' => 'files', 'image_versions' => array('thumbnail' => array('upload_url' => $this->createUrl("/p3media/file/image", array('preset' => 'p3media-upload', 'path' => urlencode(Yii::app()->user->id . "/"))), 'max_width' => 80, 'max_height' => 80))); // wrapper for jQuery-file-upload/upload.php $upload_handler = new UploadHandler($options); header('Pragma: no-cache'); header('Cache-Control: private, no-cache'); header('Content-Disposition: inline; filename="files.json"'); header('X-Content-Type-Options: nosniff'); ob_start(); switch ($_SERVER['REQUEST_METHOD']) { case 'HEAD': case 'GET': $upload_handler->get(); #$contents = ob_get_contents(); $contents = "{}"; // we do not show existing files, since this list may get very long break; case 'POST': // check if file exists $upload = $_FILES[$options['field_name']]; $tmp_name = $_FILES[$options['field_name']]['tmp_name']; if (is_array($tmp_name)) { foreach ($tmp_name as $index => $value) { $model = P3Media::model()->findByAttributes(array('path' => Yii::app()->user->id . DIRECTORY_SEPARATOR . $upload['name'][$index])); $model = new P3Media(); $attributes['path'] = Yii::app()->user->id . DIRECTORY_SEPARATOR . $upload['name'][$index]; #$attributes['title'] = $upload['name'][$index]; // TODO: fix title unique check #var_dump($attributes['title']);exit; $model->attributes = $attributes; $model->validate(array('path')); if ($model->hasErrors()) { #throw new CHttpException(500, 'File exists.'); $file = new stdClass(); $file->error = ""; foreach ($model->getErrors() as $error) { $file->error .= $error[0]; } $info[] = $file; echo CJSON::encode($info); exit; } } } $upload_handler->post(); $upload_handler_output = ob_get_contents(); $result = CJSON::decode($upload_handler_output); #var_dump($result);exit; $savedMedia = $this->createMedia($result[0]['name'], $this->module->getDataPath() . DIRECTORY_SEPARATOR . $result[0]['name']); $result[0]['p3_media_id'] = $savedMedia->id; $contents = CJSON::encode($result); break; case 'DELETE': $upload_handler->delete(); $contents = ob_get_contents(); $result = $this->deleteMedia($_GET['path']); break; default: header('HTTP/1.0 405 Method Not Allowed'); $contents = ob_get_contents(); } ob_end_clean(); return $contents; }
public function post($print_response = true) { if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') { return $this->delete($print_response); } if (PWEBCONTACT_DEBUG) { modPwebcontactHelper::setLog('Uploading file'); } return parent::post($print_response); }
public function upload() { $_user = $this->uri->segment(1); $_details = $this->mFrontend->getDetailsbyURL($_user); if ($_details != false) { if ($_details->userCanUpload == '0') { exit; } } else { exit; } $this->load->helper("upload.class"); $upload_handler = new UploadHandler(); header('Pragma: no-cache'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Vary: accept'); 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'); 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'); } }
/** * blueimp jQuery plugin function for initialize upload media image purpose * @return void * @public **/ public function admin_UploadHandler() { $this->autoRender = FALSE; App::import('Vendor', 'uploadhandler'); $upload_handler = new UploadHandler(); $info = $upload_handler->post(); if (isset($info[0]->name) && !isset($info[0]->error)) { $post = $this->MediaLibrary->find('first', array('fields' => array('MediaLibrary.id'), 'order' => array('MediaLibrary.id DESC'), 'limit' => '1')); if (count($post) == 0) { $id = 1; } else { $id = $post['MediaLibrary']['id'] + 1; } $name = substr($info[0]->name, 0, strripos($info[0]->name, '.')); $path_parts = pathinfo($info[0]->name); $name = $path_parts['filename']; $type = $path_parts['extension']; $this->request->data['MediaLibrary']['id'] = $id; $this->request->data['MediaLibrary']['m_name'] = $name; $this->request->data['MediaLibrary']['m_type'] = $type; $this->request->data['MediaLibrary']['m_size'] = $info[0]->size; $this->request->data['MediaLibrary']['m_url'] = "upload/img/" . $name . "." . $type; $this->request->data['MediaLibrary']['m_used'] = 0; $this->request->data['MediaLibrary']['m_u_id_created'] = $this->user['id']; $this->request->data['MediaLibrary']['m_date_created'] = date('Y-m-d H:i:s'); $this->MediaLibrary->create(); $this->MediaLibrary->save($this->request->data); // rename the filename... //rename( WWW_ROOT.'upload'.DS.'img'.DS.$info[0]->name , WWW_ROOT.'upload'.DS.'img'.DS.$name.'.'.$type); // rename the filename... //rename( WWW_ROOT.'upload'.DS.'img'.DS.'thumbnails'.DS.$info[0]->name , WWW_ROOT.'upload'.DS.'img'.DS.'thumbnails'.DS.$name.'.'.$type); } }
public function post($print_response = true) { if (!isset($_REQUEST['_method']) or $_REQUEST['_method'] !== 'DELETE') { $this->operation = iUploaderHandler::UPLOAD; } return parent::post($print_response); }
public function uploadAction() { if ($this->getRequest()->isPost()) { $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 { $info = $upload_handler->post(); $this->_helper->json($info, true, false); } break; case 'DELETE': $upload_handler->delete(); break; default: header('HTTP/1.1 405 Method Not Allowed'); } } }
/** * uploadFile method * Esta funcion es la encargada de gestionar los ficheros del * usurio. * En projectos add gestiona (crear,eliminar) * En projectos edit gestiona (crear) dado que los ficheros se eliminan de la BD * La direccion de la carpeta del usuario se establece con la variable * Configure::read('uploadFilesPath') y el mail del usuario (e mail es unico) * @require App::uses('Folder', 'Utility'); * @require App::uses('File', 'Utility'); * @require UploadHandler.php * @throws exception * @return void */ public function uploadFile($projectId = null) { App::import('Vendor', 'uploader', array('file' => 'jQuery-File-Upload' . DS . 'UploadHandler.php')); App::uses('Folder', 'Utility'); App::uses('File', 'Utility'); $uploadPath = Configure::read('uploadFilesPath'); $filesAllowed = Configure::read('filesAllowed'); $maxUploads = Configure::read('max_upload_files'); $maxFileSize = $this->filesize2bytes(Configure::read('max_file_size')); if ($maxUploads == 0) { $maxUploads = 99999; } $path = $uploadPath; //para que no moleste con los permisos //ini_set("display_errors", 0); //error_reporting(0); $this->autoRender = false; $email = $this->Auth->user('email'); //si no esta logueado if (!$this->Auth->loggedIn()) { print "One joker!!"; exit; } else { $folder = new Folder(); //si se puede crear la carpeta if ($folder->create($path)) { //chmod($path, 0600); // $path = $path . DS . $email; $path = $path . DS . tempnam(sys_get_temp_dir(), ''); if ($folder->create($path)) { //si no existe la carpeta se crea $folder = new Folder($path, true, 0700); //chmod($path, 0600); $absolutePath = $folder->path . DS; $options = array('script_url' => Router::url(array('controller' => 'ProjectResources', 'action' => 'uploadFile')), 'upload_dir' => $absolutePath, 'upload_url' => $this->webroot . $path . DS, 'user_dirs' => false, 'mkdir_mode' => 0700, 'param_name' => 'files', 'delete_type' => 'DELETE', 'access_control_allow_origin' => '*', 'access_control_allow_credentials' => false, 'access_control_allow_methods' => array('OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'), 'access_control_allow_headers' => array('Content-Type', 'Content-Range', 'Content-Disposition'), 'download_via_php' => false, 'accept_file_types' => '/(\\.|\\/)' . $filesAllowed . '$/i', 'max_file_size' => $maxFileSize, 'min_file_size' => 1, 'max_number_of_files' => $maxUploads, 'max_width' => null, 'max_height' => null, 'min_width' => 1, 'min_height' => 1, 'discard_aborted_uploads' => true, 'orient_image' => false); $upload_handler = new UploadHandler($options, false); switch ($_SERVER['REQUEST_METHOD']) { case 'HEAD': case 'GET': throw new Exception(); $upload_handler->get(); break; case 'POST': case 'PUT': $group_id = $this->Session->read('group_id'); if ($group_id == 1) { $this->ProjectResource->Project->id = $projectId; if (!$this->ProjectResource->Project->exists()) { throw new NotFoundException(__('Invalid project ')); } $response = $upload_handler->post(); $packagedFiles = array(); $files = $folder->find('.*.' . $filesAllowed); if (!empty($files)) { foreach ($files as $file) { $file = new File($folder->pwd() . DS . $file, 644); if ($file->readable()) { // $md5 = $file->md5(); $name = $file->name(); $ext = $file->ext(); $content = $file->read(); $fileSize = $file->size(); $file->close(); $data = array('name' => $name, 'file' => $content, 'extension' => $ext, 'project_id' => $projectId, 'size' => $fileSize); $this->ProjectResource->create(); if ($this->ProjectResource->save($data)) { $packagedFiles[$name . "." . $ext] = $this->ProjectResource->id; } } } if (!empty($packagedFiles)) { $files = $response['files']; $size = sizeof($files); for ($index = 0; $index < $size; $index++) { $file = $files[$index]; if (isset($packagedFiles[$file->name])) { $file->url = Router::url(array('controller' => 'ProjectResources', 'action' => 'downloadFile', $packagedFiles[$file->name], $projectId)); $file->deleteUrl = Router::url(array('controller' => 'ProjectResources', 'action' => 'deleteFile', $packagedFiles[$file->name], $projectId)); } else { $file->error = "Could not be saved"; } } return $this->correctResponseJson($response); // $this->correctResponseJson(array("error" => "Could not be saved")); } } if (!$folder->delete()) { throw new Exception("Error deleting files"); } return $this->correctResponseJson($response); } break; case 'DELETE': break; default: // header('HTTP/1.0 405 Method Not Allowed'); } exit; } } else { throw new Exception(); } } }
public function _loader() { $upload_handler = new UploadHandler(); 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'); //$fp=fopen("log.txt","w"); //fwrite($fp,"QUEST:".$_POST["upselect"]); //fclose($fp); switch ($_SERVER['REQUEST_METHOD']) { case 'OPTIONS': break; case 'HEAD': case 'GET': /*$fp=fopen("log.txt","w"); fwrite($fp,"QUEST:".$_GET["name"]); fclose($fp);*/ $upload_handler->get($_GET["name"]); break; case 'POST': $upload_handler->post(); //写入数据库。其中imagegroupID从$_POST["upselect"]得到,imageurl从$upload_handler->filepathout得到。 if (!$upload_handler->error) { $name = $upload_handler->name; $url = $upload_handler->filepathout; $fp = fopen("log.txt", "a"); fwrite($fp, "NEW:" . $url . "\r\n"); fclose($fp); $groupID = $_POST["upselect"]; $imgmd = new image(); $data = array($name, "", $_SESSION["USERID"], date("Y-m-d"), $url, $groupID, '', ''); $imgmd->model->New($data); $act = new active(); $img = new stdClass(); $img->gid = $groupID; $img->d = $url; $img->ti = time(); $img->gn = "xxxx"; $act->_new($_SESSION["USERID"], 1, $img); } break; case 'DELETE': $upload_handler->delete(); $file_name = isset($_REQUEST['file']) ? basename(stripslashes($_REQUEST['file'])) : null; $url = $file_name; $imgmd = new image(); $imgmd->model->Del_By_imgurl($file_name); $act = new active(); $img = new stdClass(); $img->d = $url; $img->ti = time(); $act->_del($_SESSION['USERID'], $img); break; default: header('HTTP/1.1 405 Method Not Allowed'); } }
* @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 { // Unlink file
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 { if (isset($_POST['uuid']) && isset($_POST['idUsuario']) && isset($_POST['idCurso']) && isset($_POST['idTema'])) { $info = $upload_handler->post(); $file = $info[0]; $uuid = $_POST['uuid']; $idUsuario = $_POST['idUsuario']; $idCurso = $_POST['idCurso']; $idTema = $_POST['idTema']; $clase = crearClase($idUsuario, $idCurso, $uuid, $idTema, $file->name, $file->type); if (!is_null($clase)) { //$file->url = $clase->archivo; $file->url = "#"; $file->delete_url = "#"; $file->error = ""; $file->errorDetalle = ""; } else { $file->error = " "; $file->errorDetalle = "Ocurrió un error al agregar el contenido. Intenta de nuevo más tarde";
$http = eZHTTPTool::instance(); $canUpload = true; if ($parentNodeID > 0) { $parentNode = eZContentObjectTreeNode::fetch($parentNodeID); $canUpload = $parentNode instanceof eZContentObjectTreeNode && $parentNode->canCreate(); } $response = array(); if ($canUpload) { $siteaccess = eZSiteAccess::current(); $options['upload_dir'] = eZSys::cacheDirectory() . '/fileupload/'; $options['download_via_php'] = true; $options['param_name'] = "files"; $options['image_versions'] = array(); $options['max_file_size'] = $http->variable("upload_max_file_size", null); $uploadHandler = new UploadHandler($options, false); $data = $uploadHandler->post(false); foreach ($data[$options['param_name']] as $file) { $filePath = $options['upload_dir'] . $file->name; $behaviour = new ezpContentPublishingBehaviour(); $behaviour->isTemporary = true; $behaviour->disableAsynchronousPublishing = false; ezpContentPublishingBehaviour::setBehaviour($behaviour); $upload = new eZContentUpload(); $upload->handleLocalFile($response, $filePath, $parentNodeID, false); } $file = eZClusterFileHandler::instance($filePath); if ($file->exists()) { $file->delete(); } } else { $response = array('errors' => array('Not Allowed'));
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; } }
/** * * 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; }
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); }