本文整理汇总了PHP中UploadHandler类的典型用法代码示例。如果您正苦于以下问题:PHP UploadHandler类的具体用法?PHP UploadHandler怎么用?PHP UploadHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UploadHandler类的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: handleSave
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));
}
示例5: upload
public function upload($options = null)
{
if (!isset($options['print_response'])) {
$options['print_response'] = false;
}
$upload = new \UploadHandler($options);
return $upload->get_response();
}
示例6: getLocalFileDetails
function getLocalFileDetails()
{
// Initializing normal file upload handler
$upload_handler = new UploadHandler();
$fileDetails = $upload_handler->post(false);
$fileDetails["uploadDir"] = $_POST['folderName'];
return $fileDetails;
}
示例7: processupload
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);
}
示例8: init
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/";
}
示例9: init
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);
}
示例10: trim_file_name
/**
* 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;
}
示例11: handle_file_upload
/**
* 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;
}
示例12: handle_file_upload
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;
}
示例13: __construct
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);
}
示例14: array
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);
}
示例15: set_file_delete_properties
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);
}
}