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; }
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); }
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'); }
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'); } }
/** * We should remove the unused directory after deleting a file */ public function delete() { parent::delete(); $dir = $this->options['upload_dir']; // Check that the upload dir has no files in it $empty = true; foreach (glob("{$dir}/*") as $item) { if (is_file($item)) { $empty = false; } } // There are no uploaded files in this directory, nuke it // - we need to use rm -rf because it still contains sub-dirs and meta data if ($empty) { exec("rm -rf {$dir}"); } }
public function delete($print_response = true) { $response = parent::delete(false); $mapper = Core::model('Core/Attachment'); foreach ($response as $code => $deleted) { if ($deleted) { $mapper->deleteByCode($code); } } //exit; return $this->generate_response($response, $print_response); }
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 delete($print_response = true) { if (PWEBCONTACT_DEBUG) { modPwebcontactHelper::setLog('Deleting file'); } return parent::delete($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'); } }
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'); } } }
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'); } }