Example #1
0
 public function editorupload()
 {
     $CRUD_AUTH = $this->session->userdata('CRUD_AUTH');
     if (empty($CRUD_AUTH)) {
         exit;
     }
     if (isset($_GET['CKEditorFuncNum'])) {
         require FCPATH . '/application/third_party/scrud/class/FileUpload.php';
         $msg = '';
         // Will be returned empty if no problems
         $callback = $_GET['CKEditorFuncNum'];
         // Tells CKeditor which function you are executing
         $fileUpload = new FileUpload();
         $fileUpload->uploadDir = __IMAGE_UPLOAD_REAL_PATH__;
         $fileUpload->extensions = array('.bmp', '.jpeg', '.jpg', '.png', '.gif');
         $fileUpload->tmpFileName = $_FILES['upload']['tmp_name'];
         $fileUpload->fileName = $_FILES['upload']['name'];
         $fileUpload->httpError = $_FILES['upload']['error'];
         if ($fileUpload->upload()) {
             $image_url = __MEDIA_PATH__ . "images/" . $fileUpload->newFileName;
         }
         $error = $fileUpload->getMessage();
         if (!empty($error)) {
             $msg = 'error : ' . implode("\n", $error);
         }
         $output = '<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction(' . $callback . ', "' . $image_url . '","' . $msg . '");</script>';
         echo $output;
     }
 }
function upload()
{
    $path = "./uploads/";
    //设置图片上传路径
    $up = new FileUpload($path);
    //创建文件上传类对象
    if ($up->upload('pic')) {
        //上传图片
        $filename = $up->getFileName();
        //获取上传后的图片名
        $img = new Image($path);
        //创建图像处理类对象
        $img->thumb($filename, 300, 300, "");
        //将上传的图片都缩放至在300X300以内
        $img->thumb($filename, 80, 80, "icon_");
        //缩放一个80x80的图标,使用icon_作前缀
        $img->watermark($filename, "logo.gif", 5, "");
        //为上传的图片加上图片水印
        return array(true, $filename);
        //如果成功返回成功状态和图片名称
    } else {
        return array(false, $up->getErrorMsg());
        //如果失败返回失败状态和错误消息
    }
}
Example #3
0
 public function actionUpdate($id)
 {
     $model = ARGroupon::model()->findByPk($id);
     if ($model == null) {
         $this->go('该商品不存在', Yii::app()->request->urlReferrer);
     }
     $model->setScenario('sell');
     $this->performAjaxValidation($model);
     if (!empty($_POST['ARGroupon'])) {
         //            dump($_FILES);
         //            dump($_POST);exit;
         $model->attributes = $_POST['ARGroupon'];
         if ($model->validate()) {
             $fileUpload = new FileUpload(array($model, 'image'), 'upload/groupon');
             if (!$fileUpload->isNull()) {
                 $filename = $fileUpload->save();
                 if ($filename) {
                     $model->image = $filename;
                 } else {
                     dump($fileUpload->getErrors());
                     throw new CHttpException(300, '图片上传出错');
                 }
             }
             $model->begin_time = strtotime($model->begin_time);
             $model->end_time = strtotime($model->end_time);
             $model->expire_time = strtotime($model->expire_time);
             if ($model->save()) {
                 Yii::app()->user->setFlash('success', '商品修改成功');
                 //                    $url = $_POST['return_url'];
                 //                    $this->go('商品修改成功', $url, 'success');
             }
         }
     }
     $this->render('update', array('model' => $model));
 }
Example #4
0
 function m_updateCompInfo()
 {
     if (!isset($this->request['bill_state_id']) || empty($this->request['bill_state_id'])) {
         $this->request['bill_state_id'] = "";
     } else {
         $this->request['bill_state'] = "";
     }
     #FILE UPLOADING START
     if ($this->libFunc->checkImageUpload("image1") && $_FILES["image1"]["tmp_name"] != "") {
         $fileUpload = new FileUpload();
         $fileUpload->source = $_FILES["image1"]["tmp_name"];
         $fileUpload->target = $this->imagePath . "company/" . $_FILES["image1"]["name"];
         $newName1 = $fileUpload->upload();
         $fileUpload->resampleImage($this->imagePath . "company/" . $newName1, 250, 250, 100);
         // [/DRK]
         if ($newName1 != false) {
             $image1 = $newName1;
         }
     } else {
         $this->obDb->query = "SELECT vLogo FROM " . COMPANYSETTINGS;
         $logo = $this->obDb->fetchQuery();
         $image1 = $logo[0]->vLogo;
     }
     #INSERTING COMPANY DETAILS
     $this->obDb->query = "UPDATE " . COMPANYSETTINGS . " SET \n\t\tvCname ='" . $this->libFunc->m_addToDB($this->request['storeName']) . "',\n\t\tvAddress ='" . $this->libFunc->m_addToDB($this->request['storeAddress']) . "',\n\t\tvCity ='" . $this->libFunc->m_addToDB($this->request['storeCity']) . "',\n\t\tvState='" . $this->libFunc->m_addToDB($this->request['bill_state_id']) . "',\n\t\tvStateName='" . $this->libFunc->m_addToDB($this->request['bill_state']) . "',\n\t\tvCountry='" . $this->libFunc->m_addToDB($this->request['bill_country_id']) . "',\n\t\tvZip='" . $this->libFunc->m_addToDB($this->request['storeZip']) . "',\n\t\tvFax  ='" . $this->libFunc->m_addToDB($this->request['storeFax']) . "',\n\t\tvPhone ='" . $this->libFunc->m_addToDB($this->request['storePhone']) . "',\n\t\tvFreePhone  ='" . $this->libFunc->m_addToDB($this->request['storeTollFree']) . "',\n\t\tvVatNumber  ='" . $this->libFunc->m_addToDB($this->request['vatNumber']) . "',\n\t\tvRNumber  ='" . $this->libFunc->m_addToDB($this->request['companyNumber']) . "',\n\t\tvSlogan  ='" . $this->libFunc->m_addToDB($this->request['companySlogan']) . "',\n\t\tvLogo  ='" . $image1 . "'";
     $this->obDb->updateQuery();
     $this->libFunc->m_mosRedirect(SITE_URL . "admin/adminindex.php?action=settings.company&msg=1");
 }
Example #5
0
 public function actionUpdate($id)
 {
     $model = $this->loadBiz(trim($id));
     $model->setScenario('sell');
     $this->performAjaxValidation($model);
     if (!empty($_POST)) {
         $model->attributes = $_POST['ARBiz'];
         //            dump($_FILES);
         //            控制器中使用实例如下:
         $upload = new FileUpload(array($model, 'license_photo'), 'upload/groupon');
         //model处理文件上传  $upload = new FileUpload(array($model,'pic'),'upload/goods');
         if (!$upload->isNull()) {
             if ($filename = $upload->save()) {
                 $model->license_photo = $filename;
                 //                      dump($filename);
             } else {
                 print_r($upload->getErrors());
                 throw new CHttpException('300', '文件上传失败');
             }
         }
         //            dump($model->attributes);
         if ($model->save()) {
             //                $return_url = $_POST['return_url'];
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }
Example #6
0
 public function preform()
 {
     $uploadFile = new FileUpload();
     $uploadFile->set("path", "./images/");
     $uploadFile->set("maxsize", 2000000);
     $uploadFile->set("allowtype", array("gif", "png", "jpg", "jpeg"));
     $uploadFile->set("israndname", false);
 }
 /**
  * installs an uploaded template
  */
 function _performUploadTemplate()
 {
     // handle the uploaded file
     $files = HttpVars::getFiles();
     $uploads = new FileUploads($files);
     if (count($files) == 0 || $files["templateFile"]["name"] == "") {
         $this->_view = new AdminTemplatedView($this->_blogInfo, "newglobaltemplate");
         $this->_view->setValue("templateFolder", TemplateSetStorage::getBaseTemplateFolder());
         $this->_view->setErrorMessage($this->_locale->tr("error_must_upload_file"));
         $this->setCommonData();
         return false;
     }
     $config =& Config::getConfig();
     $tmpFolder = $config->getValue('temp_folder');
     // move it to the temporary folder
     $result = $uploads->process($tmpFolder);
     // and from there, unpack it
     $upload = new FileUpload($files['templateFile']);
     $templateSandbox = new TemplateSandbox();
     $valid = $templateSandbox->checkTemplateSet($upload->getFileName(), $tmpFolder . '/');
     if ($valid < 0) {
         $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
         $this->_view->setErrorMessage($this->_checkTemplateSandboxResult($valid));
         $this->setCommonData();
         return false;
     }
     // the template was ok, so then we can proceed and move it to the main
     // template folder, add it to our array of templates
     //
     // :KLUDGE:
     //
     // maybe we should simply move the files rather than unpacking the whole
     // thing again, but this indeed makes things easier! ;)
     $unpacker = new Unpacker();
     $templateFolder = $config->getValue('template_folder');
     $fileToUnpack = $tmpFolder . '/' . $upload->getFileName();
     if (!$unpacker->unpack($fileToUnpack, $templateFolder)) {
         $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
         $tf = new Textfilter();
         $this->_view->setErrorMessage($this->_locale->pr('error_installing_template', $tf->filterAllHtml($upload->getFileName())));
         $this->setCommonData();
         return false;
     }
     // if the template set was installed ok in the template folder, we can record
     // it as a valid set
     $ts = new TemplateSetStorage();
     $fileParts = explode(".", $upload->getFileName());
     $templateName = $fileParts[0];
     $ts->addTemplate($templateName);
     $this->_view = new AdminSiteTemplatesListView($this->_blogInfo);
     $this->_view->setSuccessMessage($this->_locale->pr('template_installed_ok', $templateName));
     $this->setCommonData();
     return true;
 }
 /**
  * 处理上传图片,重命名放到指定目录下,这里这个函数用来上传用户头像
  * */
 public function image()
 {
     //上传控件的名称是upload
     $fileUpload = new FileUpload('upload', $_POST['MAX_FILE_SIZE']);
     $ckefn = $_GET['CKEditorFuncNum'];
     $path = $fileUpload->getPath();
     $img = new Image($path);
     $img->ckeImg(650, 0);
     $img->out();
     echo "<script>window.parent.CKEDITOR.tools.callFunction({$ckefn},\"{$path}\", '图片上传成功')</script>";
 }
 public function edit($data)
 {
     if (isset($data['artist_image'])) {
         $imgUploader = new FileUpload($data['artist_image']['name'], $data['artist_image']['tmp_name']);
         $l_sNewFileName = $imgUploader->image(ROOT . '/public/assets/artist/');
         $imgUploader->image(ROOT . '/public/assets/artist/thumb/', 275, 322, $data['cropped'][0], $data['cropped'][1], $data['cropped'][2], $data['cropped'][3]);
         $this->db->update('artist', array('artist_name' => $data['artist_name'], 'artist_active' => $data['artist_active'], 'artist_website' => $data['artist_website'], 'artist_featured' => $data['artist_featured'], 'artist_country' => $data['artist_country'], 'artist_description' => $data['artist_description'], 'artist_image' => $l_sNewFileName), "artist_id = {$data['artist_id']}");
     } else {
         $this->db->update('artist', array('artist_name' => $data['artist_name'], 'artist_active' => $data['artist_active'], 'artist_website' => $data['artist_website'], 'artist_featured' => $data['artist_featured'], 'artist_country' => $data['artist_country'], 'artist_description' => $data['artist_description']), "artist_id = {$data['artist_id']}");
     }
 }
 public function editSave($data)
 {
     if (isset($data['article_img'])) {
         $imgUploader = new FileUpload($data['article_img']['name'], $data['article_img']['tmp_name']);
         $l_sNewFileName = $imgUploader->image(ROOT . '/public/assets/product/');
         $imgUploader->image(ROOT . '/public/assets/product/thumb/', 218, 129, $data['cropped'][0], $data['cropped'][1], $data['cropped'][2], $data['cropped'][3]);
         $this->db->update('article', array('article_name' => $data['article_name'], 'article_price' => $data['article_price'], 'article_date' => $data['article_date'], 'category_id' => $data['category_id'], 'article_featured' => $data['article_featured'], 'artist_id' => $data['artist_id'], 'article_description' => $data['article_description'], 'article_img' => $l_sNewFileName), "article_id = {$data['article_id']}");
     } else {
         $this->db->update('article', array('article_name' => $data['article_name'], 'article_price' => $data['article_price'], 'article_date' => $data['article_date'], 'category_id' => $data['category_id'], 'article_featured' => $data['article_featured'], 'artist_id' => $data['artist_id'], 'article_description' => $data['article_description']), "article_id = {$data['article_id']}");
     }
 }
 private static function editCuadro($gestor, $sesion)
 {
     $obra = new Obra();
     $obra->read();
     $pkID = Request::post("pkID");
     $nombre = Request::post("nombre");
     $email = Request::post('email');
     $usuario = $sesion->getUser();
     $obra->setId_usuario($usuario);
     /*Subir fotografia*/
     $subir = new FileUpload("nuevaImagen");
     $subir->setDestino("../../controlUsuario/cuadros/{$usuario}/");
     $subir->setTamaño(100000000);
     $subir->setNombre($nombre);
     $subir->setPolitica(FileUpload::REEMPLAZAR);
     if ($subir->upload()) {
         echo 'Archivo subido con éxito';
         $obra->setImagen($nombre . "." . $subir->getExtension());
     } else {
         echo 'Archivo no subido';
     }
     $obra->setImagen($nombre . "." . $subir->getExtension());
     $r = $gestor->set($obra, $pkID);
     echo $r;
     //header("Location:index.php?op=edit&r=$r");
 }
 /**
  * Uploaded files are POSTed here
  */
 public function uploadAction()
 {
     require_once 'models/table/File.php';
     $return = array();
     if (isset($_FILES['upload'])) {
         if (!$_FILES['upload']['error']) {
             // Check for upload directory
             $uploadDir = $this->getUploadDir();
             $name = $this->checkFile($_FILES['upload']['name']);
             move_uploaded_file($_FILES['upload']['tmp_name'], "{$uploadDir}/{$name}");
             $data['parent_id'] = $_POST['parent_id'];
             $data['parent_table'] = $_POST['parent_table'];
             $data['filemime'] = $_FILES['upload']['type'];
             $data['filesize'] = $_FILES['upload']['size'];
             $data['filename'] = $name;
             $fileTable = new File();
             $data['id'] = $fileTable->insert($data);
             $data['creator_name'] = $this->view->identity->first_name . ' ' . $this->view->identity->last_name;
             $dataArray = FileUpload::modifyRows(array($data));
             $return = $dataArray[0];
             // Strange JSON decoding error when sending hyperlink
             $return['filename'] = strip_tags($return['filename']);
         } else {
             $return['error'] = 'Error uploading file. id: ' . $_FILES['upload']['error'];
         }
     }
     require_once 'Zend/Json.php';
     echo Zend_Json::encode($return);
     exit;
 }
 public function indexAction()
 {
     $this->_redirect('employee/search');
     exit;
     ## old dash function
     if (!$this->hasACL('edit_employee')) {
         $this->doNoAccessError();
     }
     require_once 'models/table/dash-employee.php';
     $this->view->assign('title', $this->translation['Application Name'] . space . t('Employee Tracking System'));
     // restricted access?? does this user only have acl to view some trainings or people
     // they dont want this, removing 5/01/13
     ##		$org_allowed_ids = allowed_org_access_full_list($this); // doesnt have acl 'training_organizer_option_all'?
     ##		$allowedWhereClause = $org_allowed_ids ? " partner.organizer_option_id in ($org_allowed_ids) " : "";
     // restricted access?? only show organizers that belong to this site if its a multi org site
     ##		$site_orgs = allowed_organizer_in_this_site($this); // for sites to host multiple training organizers on one domain
     ##		$allowedWhereClause .= $site_orgs ? " AND partner.organizer_option_id in ($site_orgs) " : "";
     $institute = new DashviewEmployee();
     $details = $institute->fetchdetails($org_allowed_ids);
     $this->view->assign('getins', $details);
     /****************************************************************************************************************/
     /* Attached Files */
     require_once 'views/helpers/FileUpload.php';
     $PARENT_COMPONENT = 'employee';
     FileUpload::displayFiles($this, $PARENT_COMPONENT, 1, $this->hasACL('admin_files'));
     // File upload form
     if ($this->hasACL('admin_files')) {
         $this->view->assign('filesForm', FileUpload::displayUploadForm($PARENT_COMPONENT, 1, FileUpload::$FILETYPES));
     }
     /****************************************************************************************************************/
 }
Example #14
0
 public function ckeUp()
 {
     if (isset($_GET['type'])) {
         //查看了源代码,他的名称是:upload
         $_fileupload = new FileUpload('upload', $_POST['MAX_FILE_SIZE']);
         $_ckefn = $_GET['CKEditorFuncNum'];
         $_path = $_fileupload->getPath();
         $_img = new Image($_path);
         $_img->ckeImg(650, 0);
         $_img->out();
         echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction({$_ckefn},\".{$_path}\",'图片上传成功!');</script>";
         exit;
     } else {
         Tool::alertBack('警告:由于非法操作导致上传失败!');
     }
 }
 public function edit($data)
 {
     $dataArray = array('event_name' => $data['event_name'], 'event_date' => $data['event_date'], 'event_date_end' => $data['event_date_end'], 'event_description' => $data['event_description']);
     if (isset($data['event_image']) || isset($data['event_file'])) {
         if (isset($data['event_image'])) {
             $imgUploader = new FileUpload($data['event_image']['name'], $data['event_image']['tmp_name']);
             $l_sNewFileName = $imgUploader->image(ROOT . '/public/assets/event/');
             $imgUploader->image(ROOT . '/public/assets/event/thumb/', 275, 163, $data['cropped'][0], $data['cropped'][1], $data['cropped'][2], $data['cropped'][3]);
             $dataArray['event_image'] = $l_sNewFileName;
         }
         if (isset($data['event_file'])) {
             $fileUploader = new FileUpload($data['event_file']['name'], $data['event_file']['tmp_name']);
             $l_sNewFileName = $fileUploader->file(ROOT . '/public/assets/file/');
             $dataArray['event_file'] = $l_sNewFileName;
         }
         $this->db->update('event', $dataArray, "event_id = {$data['event_id']}");
     } else {
         $this->db->update('event', $dataArray, "event_id = {$data['event_id']}");
     }
 }
Example #16
0
 public function testSingleUpload()
 {
     $playground_path = __DIR__ . '/../playground';
     $server = array('CONTENT_TYPE' => 'image/jpg', 'CONTENT_LENGTH' => 30321);
     $file = array('tmp_name' => $playground_path . '/real-image.jpg', 'name' => 'real-image.jpg', 'size' => 30321, 'type' => 'image/jpg', 'error' => 0);
     $filesystem = new FileSystem\Mock();
     $resolver = new PathResolver\Simple($playground_path . '/uploaded');
     $uploader = new FileUpload($file, $server);
     $test = false;
     $uploader->setPathResolver($resolver);
     $uploader->setFileSystem($filesystem);
     $uploader->addCallback('completed', function () use(&$test) {
         $test = true;
     });
     list($files, $headers) = $uploader->processAll();
     $this->assertCount(1, $files, 'Files array should contain one file');
     $this->assertEquals(0, $files[0]->error, 'Uploaded file should not have errors');
     $this->assertNotEmpty($files[0]->path, 'Uploaded file should have path');
     $this->assertTrue($test, 'Complete callback should set $test to true');
 }
 /**
  * Return an object property
  *
  * @param string
  *
  * @return mixed
  */
 public function __get($strKey)
 {
     switch ($strKey) {
         case 'name':
             return $this->strName;
             break;
     }
     if (isset($this->arrData[$strKey])) {
         return $this->arrData[$strKey];
     }
     return parent::__get($strKey);
 }
Example #18
0
 /**
  * Validate the upload
  * @return string
  */
 public function validateUpload()
 {
     \Message::reset();
     $objUploader = new \FileUpload();
     $objUploader->setName($this->strName);
     $uploadFolder = $this->strTempFolder;
     // Convert the $_FILES array to Contao format
     if (!empty($_FILES[$this->strName])) {
         $pathinfo = pathinfo(strtolower($_FILES[$this->strName]['name']));
         $strCacheName = standardize($pathinfo['filename']) . '.' . $pathinfo['extension'];
         $uploadFolder = $this->strTempFolder . '/' . substr($strCacheName, 0, 1);
         if (is_file(TL_ROOT . '/' . $uploadFolder . '/' . $strCacheName) && md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $_FILES[$this->strName]['name']) != md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $strCacheName)) {
             $strCacheName = standardize($pathinfo['filename']) . '-' . substr(md5_file(TL_ROOT . '/' . $uploadFolder . '/' . $_FILES[$this->strName]['name']), 0, 8) . '.' . $pathinfo['extension'];
             $uploadFolder = $this->strTempFolder . '/' . substr($strCacheName, 0, 1);
         }
         \Haste\Haste::mkdirr($uploadFolder);
         $arrFallback = $this->getFallbackData();
         // Check that image is not assigned in fallback language
         if (is_array($arrFallback) && in_array($strCacheName, $arrFallback)) {
             $this->addError($GLOBALS['TL_LANG']['ERR']['imageInFallback']);
         }
         $_FILES[$this->strName] = array('name' => array($strCacheName), 'type' => array($_FILES[$this->strName]['type']), 'tmp_name' => array($_FILES[$this->strName]['tmp_name']), 'error' => array($_FILES[$this->strName]['error']), 'size' => array($_FILES[$this->strName]['size']));
     }
     $varInput = '';
     try {
         $varInput = $objUploader->uploadTo($uploadFolder);
     } catch (\Exception $e) {
         $this->addError($e->getMessage());
     }
     if ($objUploader->hasError()) {
         foreach ($_SESSION['TL_ERROR'] as $strError) {
             $this->addError($strError);
         }
     }
     \Message::reset();
     if (!is_array($varInput) || empty($varInput)) {
         $this->addError($GLOBALS['TL_LANG']['MSC']['mmUnknownError']);
     }
     return $varInput[0];
 }
 /**
  * Goes through the array of files and processes them accordingly.
  * The result is an array of the appropiate Resource class that has been
  * created using the ResourceFactory class.
  *
  * @return An array of Upload objects that have already been moved to a safer
  * location.
  */
 function process($destinationFolder)
 {
     // first, check if the upload feature is available
     $config =& Config::getConfig();
     if (!$config->getValue("uploads_enabled")) {
         return FILE_UPLOADS_NOT_ENABLED;
     }
     // array used to store the files that have already been saved
     $uploads = array();
     if ($destinationFolder[strlen($destinationFolder - 1)] != "/") {
         $destinationFolder .= "/";
     }
     foreach ($this->_files as $file) {
         $upload = new FileUpload($file);
         $fileName = $upload->getFileName();
         if ($this->my_move_uploaded_file($upload->getTmpName(), $destinationFolder . $fileName)) {
             $upload->setFolder($destinationFolder);
             $upload->setError(0);
         } else {
             $upload->setError(1);
         }
         array_push($uploads, $upload);
     }
     return $uploads;
 }
Example #20
0
 public function __construct($opts, $form)
 {
     parent::__construct($opts, $form);
     // make sure we have the thumb_path, if not default it to the upload path
     if ($this->make_thumb === true) {
         if ($this->thumb_path == null) {
             $this->thumb_path = $this->upload_path;
         }
         if ($this->thumb_name == null) {
             throw new \Exception('Thumb name not set for ' . $this->name);
         }
     }
 }
Example #21
0
 /**
  * MimeType validator: has file specified mime type?
  * @param  FileUpload
  * @param  array|string  mime type
  * @return bool
  */
 public static function validateMimeType(FileUpload $control, $mimeType)
 {
     $file = $control->getValue();
     if ($file instanceof HttpUploadedFile) {
         $type = strtolower($file->getContentType());
         $mimeTypes = is_array($mimeType) ? $mimeType : explode(',', $mimeType);
         if (in_array($type, $mimeTypes, TRUE)) {
             return TRUE;
         }
         if (in_array(preg_replace('#/.*#', '/*', $type), $mimeTypes, TRUE)) {
             return TRUE;
         }
     }
     return FALSE;
 }
 public function testCreateAndRetrieveCurlFile()
 {
     if (!class_exists('\\CurlFile', false)) {
         // Older PHP versions don't support this
         return;
     }
     $curlFile = new \CurlFile(dirname(__FILE__) . '/../data/test.png');
     self::authorizeFromEnv();
     $file = FileUpload::create(array('purpose' => 'dispute_evidence', 'file' => $curlFile));
     $this->assertSame(95, $file->size);
     $this->assertSame('png', $file->type);
     // Just check that we don't get exceptions
     $file = FileUpload::retrieve($file->id);
     $file->refresh();
 }
Example #23
0
 function m_uploadImage()
 {
     $fileUpload = new FileUpload();
     $libFunc = new c_libFunctions();
     $this->obDb->query = "select iVendorid_PK,vImage from " . SUPPLIERS . " where iVendorid_PK = " . $this->request['id'];
     $row_code = $this->obDb->fetchQuery();
     if ($this->libFunc->checkImageUpload("image")) {
         $fileUpload->source = $_FILES["image"]["tmp_name"];
         $fileUpload->target = $this->imagePath . "suppliers/" . $_FILES["image"]["name"];
         $newName1 = $fileUpload->upload();
         if ($newName1 != false) {
             $image = $newName1;
         }
         if (!empty($row_code[0]->vImage)) {
             $fileUpload->deleteFile($this->imagePath . "suppliers/" . $row_code[0]->vImage);
         }
         $imagename = "image";
     } else {
         $image = $row_code[0]->vImage;
     }
     $this->obDb->query = "UPDATE " . SUPPLIERS . " SET `vImage`='{$image}', `tmEditDate`='" . time() . "', `iAdminUser` ='" . $_SESSION['uid'] . "' where iVendorid_PK ='" . $this->request['id'] . "'";
     $this->obDb->updateQuery();
     $this->libFunc->m_mosRedirect(SITE_URL . "user/adminindex.php?action=supplier.uploadForm&status=1&id=" . $this->request['id']);
 }
 public function __construct($name, $maxSize, $allowedExts)
 {
     $this->ok = true;
     if (!isset($_FILES[$name]) || !isset($_FILES[$name]['error']) || is_array($_FILES[$name]['error'])) {
         $this->error = 'Ongeldige upload.';
         $this->ok = false;
         return;
     }
     switch ($_FILES[$name]['error']) {
         case UPLOAD_ERR_OK:
             break;
         case UPLOAD_ERR_NO_FILE:
             $this->error = 'Geen bestand ontvangen!';
             $this->ok = false;
             return;
         case UPLOAD_ERR_INI_SIZE:
         case UPLOAD_ERR_FORM_SIZE:
             $this->error = 'Het ontvangen bestand is te groot!' . 'Maximale grootte: ' . FileUpload::humanFormat($maxSize);
             $this->ok = false;
             return;
         default:
             $this->error = 'Er is een onbekende fout opgetreden.';
             $this->ok = false;
             return;
     }
     if ($_FILES[$name]['size'] > $maxSize) {
         $this->error = 'Het ontvangen bestand is te groot!' . 'Maximale grootte: ' . FileUpload::humanFormat($maxSize);
         $this->ok = false;
         return;
     }
     $pi = pathinfo($_FILES[$name]['name']);
     if (!in_array($pi['extension'], $allowedExts)) {
         $this->error = 'Dit formaat is niet toegestaan! Toegestane extensies:' . implode(', ', $allowedExts);
         $this->ok = false;
         return;
     }
     $this->mimeType = $_FILES[$name]['type'];
     $this->id = uniqid();
     $this->filename = DN_ROOT . '/attachments/' . $this->id;
     if (!@move_uploaded_file($_FILES[$name]['tmp_name'], $this->filename)) {
         $this->error = 'Er is iets misgegaan bij het opslaan van het bestand.' . 'Probeer het nog eens.';
         $this->ok = false;
         return;
     }
     return true;
 }
 static function upload($nombre)
 {
     $directorio = "./img/";
     $nombreTemporal = $_FILES["archivo"]["tmp_name"];
     if (FileUpload::isImage()) {
         if (FileUpload::directory()) {
             if (file_exists($directorio . $nombre)) {
                 return move_uploaded_file($nombreTemporal, $directorio . $nombre . "(" . rand(0, 500) . ")");
             } else {
                 return move_uploaded_file($nombreTemporal, $directorio . $nombre);
             }
         } else {
             return mkdir($directorio) + move_uploaded_file($nombreTemporal, $directorio . $nombre);
         }
     } else {
         echo "<br/>No es un formato valido<br/>";
     }
 }
Example #26
0
 public function fileRead($fileName, $mode, $first_column = NULL)
 {
     if ($handle = FileUpload::uploadFile($fileName, $mode)) {
         while ($row = fgetcsv($handle, ',')) {
             if ($first_column) {
                 $column_header = $row;
                 $first_column = FALSE;
             }
             if ($first_column === FALSE) {
                 $record = array_combine($column_header, $row);
                 $records[] = $record;
             }
             if ($first_column === NULL) {
                 $records[] = $row;
             }
         }
         //end while loop
         FileUpload::fileClose($handle);
     }
     //end fileUpload if
     return $records;
 }
Example #27
0
 public function actionUpload()
 {
     include __DIR__ . "./../uploader/Uploader.php";
     $upload_dir = \Yii::$app->getModule("file")->getStorageDir();
     $uploader = new \FileUpload('uploadfile');
     $fileModel = new File();
     $realName = $_GET["uploadfile"];
     // Handle the upload
     $isUplaoded = $uploader->handleUpload($upload_dir);
     $result = false;
     $errorMsg = '';
     if ($isUplaoded) {
         $fileModel = new File();
         $fileModel->setAttribute("real_name", $realName);
         $fileModel->setAttribute("name_on_server", $uploader->getSavedFileName());
         $fileModel->setAttribute("size", $uploader->getFileSize());
         if (!$fileModel->save()) {
             $uploader->rollBack();
             $errorMsg = "Entity save error";
         } else {
             if (!empty($_GET["relateTo"])) {
                 if (!$fileModel->linkWith($_GET["relateTo"])) {
                     $uploader->rollBack();
                     $fileModel->delete();
                     $errorMsg = "Entity link error";
                 } else {
                     $result = true;
                 }
             } else {
                 $result = true;
             }
         }
     } else {
         $errorMsg = $uploader->getErrorMsg();
     }
     if ($result) {
         echo json_encode(array('success' => true));
     } else {
         exit(json_encode(['success' => false, 'msg' => $errorMsg]));
     }
 }
 function modificarObra()
 {
     $n = Request::post('nombre');
     $t = Request::post('tecnica');
     $i = Request::post('id_obra');
     $obra = $this->gestorObra->get($i);
     $lista = $this->gestorObra->getListObrasEmail($this->sesion->get("usu"));
     $formusuario = $this->plantilla->get('_formusuario');
     $formsesion = $this->plantilla->get('_formsesion');
     $obra->setNombre($n);
     $obra->setTecnica($t);
     $this->gestorObra->set($obra);
     $this->sesion->destroy();
     $fileUpload = new FileUpload($_FILES["imagen"]);
     $fileUpload->setNombre($n);
     $fileUpload->setDestino("imagenes/obras/");
     $fileUpload->upload();
     $usuario = $this->gestorUsu->get($this->sesion->get("usu"));
     $paginaDos = $this->plantilla->get('_formmod');
     $campos = "";
     $d = array("email" => $usuario->getEmail(), "clave" => $usuario->getClave(), "alias" => $usuario->getAlias());
     $pDos = $this->plantilla->replace($d, $paginaDos);
     $pagina = $this->plantilla->get('_usuario');
     $datos = array("registro" => "", "nombresesion" => $this->sesion->get("usu"), "formsesion" => $formsesion, "datos" => $formusuario, "formmod" => $pDos, "login" => "", "mensaje" => "", "mensajesubida" => "", "mensajemod" => "", "contenidoobras" => "", "modificaobra" => "", "mensajemodobra" => "Operación realizada correctamente.");
     $p = $this->plantilla->replace($datos, $pagina);
     echo $p;
 }
$userManager = new ManageUser($db);
$sesion = new Session();
$email = Request::post("email");
$newemail = Request::post("newemail");
$pass = Request::post("pass");
$alive = Request::post("alive");
$worker = Request::post("worker");
$admin = Request::post("admin");
$newemail = $newemail === null ? $email : $newemail;
$alive = $alive === null ? 0 : 1;
$worker = $worker === null ? 0 : 1;
$admin = $admin === null ? 0 : 1;
$usuario = $userManager->get($email);
$usuario->setEmail($newemail);
$usuario->setAlias(explode("@", $newemail)[0]);
$usuario->setAlive($alive);
$usuario->setWorker($worker);
$usuario->setAdmin($admin);
if ($pass !== null) {
    $usuario->setPass($pass);
}
$photo = new FileUpload("image");
if ($photo->getError() === false) {
    $usuario->setImage("images/" . $usuario->getAlias() . ".jpg");
    $photo->setDestination("../images/");
    $photo->setName($usuario->getAlias());
    echo $photo->upload();
}
$userManager->setEmail($usuario, $email);
$sesion->destroy();
$sesion->sendRedirect("../admin.php");
Example #30
0
// If there is no menu to show
if (!defined('NOREQUIREHTML')) {
    define('NOREQUIREHTML', '1');
}
// If we don't need to load the html.form.class.php
//if (! defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX','1');
//if (! defined("NOLOGIN"))        define("NOLOGIN",'1');       // If this page is public (can be called outside logged session)
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/fileupload.class.php';
error_reporting(E_ALL | E_STRICT);
//print_r($_POST);
//print_r($_GET);
//print 'upload_dir='.GETPOST('upload_dir');
$fk_element = GETPOST('fk_element', 'int');
$element = GETPOST('element', 'alpha');
$upload_handler = new FileUpload(null, $fk_element, $element);
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':