本文整理汇总了PHP中UploadHandler::post方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadHandler::post方法的具体用法?PHP UploadHandler::post怎么用?PHP UploadHandler::post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadHandler
的用法示例。
在下文中一共展示了UploadHandler::post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
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: handle
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;
}
示例3: upload
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;
}
示例4: getLocalFileDetails
function getLocalFileDetails()
{
// Initializing normal file upload handler
$upload_handler = new UploadHandler();
$fileDetails = $upload_handler->post(false);
$fileDetails["uploadDir"] = $_POST['folderName'];
return $fileDetails;
}
示例5: post
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);
}
示例6: UploadHandler
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');
}
示例7: uploadHandler
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;
}
示例8: uploadHandler
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;
}
示例9: post
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);
}
示例10: upload
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');
}
}
示例11: admin_UploadHandler
/**
* 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);
}
}
示例12: post
public function post($print_response = true)
{
if (!isset($_REQUEST['_method']) or $_REQUEST['_method'] !== 'DELETE') {
$this->operation = iUploaderHandler::UPLOAD;
}
return parent::post($print_response);
}
示例13: uploadAction
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');
}
}
}
示例14: uploadFile
/**
* 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"));
}
}
//.........这里部分代码省略.........
示例15: _loader
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');
}
}