Example #1
0
 function changeAvatar()
 {
     if (isset($_POST['avasubmit'])) {
         $upload_dir = './images/avatars/';
         $cfile = md5($_SESSION['nickname']);
         $u = new Uploader();
         try {
             if (is_file($upload_dir . $cfile . '.jpg')) {
                 unlink($upload_dir . $cfile . '.jpg');
             }
             if (is_file($upload_dir . $cfile . '.jpeg')) {
                 unlink($upload_dir . $cfile . '.jpeg');
             }
             if (is_file($upload_dir . $cfile . '.png')) {
                 unlink($upload_dir . $cfile . '.png');
             }
             if (is_file($upload_dir . $cfile . '.gif')) {
                 unlink($upload_dir . $cfile . '.gif');
             }
             $cfile = $u->Upload('avach', $upload_dir, $cfile);
         } catch (Exception $e) {
             $error = $e->getMessage();
         }
         $sql = "UPDATE useravatar SET avatar='" . $cfile . "' WHERE id=(SELECT avatar_id FROM users WHERE id=" . $_SESSION['id'] . ");";
         $this->db->query($sql);
         $_SESSION['avatar'] = $cfile;
     }
 }
Example #2
0
    public static function fileUploadBlock()
    {
        if (self::$invalid) {
            return;
        }
        i18n::set('admin');
        $uploader = new Uploader('editFiles', 'EditPage::handleUpload', false, array('multi' => true));
        queue_js_string("/*\$(function(){\$('.view-uploads').overlay({\n\tmask: {\n\t\tcolor: '#000',\n\t\tloadSpeed: 200,\n\t\topacity: 0.7\n\t},\n\n\tcloseOnClick: true\n});});*/");
        $uploadedButton = sprintf("<a href='#' class='action view-uploads' rel='#cc_uploaded_overlay'>%s%s</a>", icon('folder_picture'), __('admin', 'view-all-files'));
        $uploadedFiles = <<<EOT
<div class="cc_uploaded_files">
{$uploadedButton}
\t<div id="cc_uploaded_overlay" class="cc_modal">
\t\t<h2>%s</h2>
\t\t<ul class="cc_file_list">
\t\t\t%s
\t\t</ul>
\t</div>
</div>
EOT;
        //foreach(Uploads::getAllFiles() as $)
        $r .= sprintf("<h3>%s</h3>%s%s", __('upload-files'), sprintf($uploadedFiles, __('uploaded-files'), $files), $uploader->createHTML());
        i18n::restore();
        return $r;
    }
Example #3
0
 public function upload()
 {
     //检查登录
     $this->_login();
     //单文件
     if (!$_FILES || $_FILES["file"]["error"] > 0) {
         echo '图片不能为空!';
         throw new Exception('exit');
     }
     //处理上传的图片
     $dir = 'goods/';
     $upload = new Uploader($_FILES, $dir);
     //保存图片
     if ($upload->save()) {
         $data['goods_photo'] = $upload->getUrl();
         //图片路径
     }
     $da = array();
     $da = $this->_getPost();
     $data_new = array_merge($data, $da);
     AdminGoodsM::add($data_new);
     //跳转到未出售商品列表
     $url = url('admin', 'admingoods::unsale');
     header('Location:' . $url);
     throw new Exception('exit');
 }
Example #4
0
 function save($package)
 {
     $Filter = new Filter();
     $name = $this->getName($Filter->get($package, 'name', null));
     if ($Filter->get($package, 'error', false)) {
         // An HTTP error occurred
         return false;
     } else {
         if (empty($name)) {
             // An empty file name was posted
             return false;
         } else {
             if ($this->exists($name)) {
                 return false;
             }
         }
     }
     $Uploader = new Uploader(array("application/zip"), array(SB_TMP_DIR));
     list($result, $tmpfile) = $Uploader->upload($package, SB_TMP_DIR);
     if (intval($result) != 1) {
         // The file was not uploaded
         return false;
     }
     if ($this->unzip($tmpfile, $this->directory)) {
         return true;
     }
     unlink($tmpfile);
     return false;
 }
Example #5
0
 function save($package)
 {
     $Filter = new Filter();
     $name = $this->getName($Filter->get($package, 'name', null));
     if ($Filter->get($package, 'error', false)) {
         // An HTTP error occurred
         return false;
     } else {
         if (empty($name)) {
             // An empty file name was posted
             return false;
         } else {
             if ($this->exists($name)) {
                 return false;
             }
         }
     }
     $Uploader = new Uploader(array("application/zip"), array(SB_TMP_DIR));
     list($result, $tmpfile) = $Uploader->upload($package, SB_TMP_DIR);
     if (intval($result) != 1) {
         // The file was not uploaded
         return false;
     }
     // handle the file move to the managers dir
     if (!FileSystem::make_dir($this->directory . $name)) {
         // The target directory could not be created
         return false;
     }
     return $this->unzip($tmpfile, $this->directory . $name);
 }
Example #6
0
 public function testUpload()
 {
     $connection = new Connection('http://localhost:5984');
     $uploader = new Uploader($connection);
     $rf = new ResponseFactory();
     $get = new GetDocument($rf);
     $doc = $get->getDocument($connection, 'test', 'doc');
     $uploader->upload('PUT', 'test/' . $doc->_id . '/keya?rev=' . $doc->_rev, 'key');
 }
Example #7
0
 function uploadImage()
 {
     $uploader = new \Uploader();
     $from = isset($_GET["from"]) ? $_GET["from"] : "default";
     $filename = $_GET["filename"];
     $info = $uploader->uploadAndPersistImage($filename, "php://input", $from);
     header('Content-Type: application/json');
     exit(json_encode($info));
 }
Example #8
0
 public function createAttachment(Uploader $uploader, $database, $id, $revision, $name, $file)
 {
     $value = $uploader->upload('PUT', $database . '/' . $id . '/' . $name . '?rev=' . $revision, $file);
     $response = $this->response_factory->make($value);
     if ($response->status() !== '201' && $response->status() !== '202') {
         throw new AttachmentCreationException();
     }
     return json_decode($response->body());
 }
Example #9
0
 /**
  * Upload image to cloudinary and return the shortened url
  * @param  Image $image 
  * @return string        shortened url
  */
 public function upload($image)
 {
     $this->intConfig();
     if (!is_null($image)) {
         $result = $this->uploader->upload($image);
         $longUrl = $result['url'];
         $this->publicId = $result['public_id'];
         $this->shortUrl = $this->shortenUrl($longUrl);
     }
 }
Example #10
0
 function uploadfile($para)
 {
     import('image.func');
     import('uploader.lib');
     $uploader = new Uploader();
     $uploader->allowed_type(IMAGE_FILE_TYPE);
     $uploader->allowed_size(2097152);
     // 2M
     $files = $para;
     //$_FILES['activity_banner'];
     if ($files['error'] == UPLOAD_ERR_OK) {
         /* 处理文件上传 */
         $file = array('name' => $files['name'], 'type' => $files['type'], 'tmp_name' => $files['tmp_name'], 'size' => $files['size'], 'error' => $files['error']);
         $uploader->addFile($file);
         if (!$uploader->file_info()) {
             $data = current($uploader->get_error());
             $res = Lang::get($data['msg']);
             $this->view_iframe();
             echo "<script type='text/javascript'>alert('{$res}');</script>";
             return false;
         }
         $uploader->root_dir(ROOT_PATH);
         $dirname = 'data/files/mall/weixin';
         $filename = $uploader->random_filename();
         $file_path = $uploader->save($dirname, $filename);
     }
     return $file_path;
 }
 public function uploadImage($image)
 {
     if (!is_null($image)) {
         $result = $this->uploader->uploadFile($image);
         $longUrl = $result['url'];
         //initialize bitly
         $this->initBitly();
         //shorten url
         $this->shortUrl = $this->shortener->shortenUrl($longUrl);
     }
 }
Example #12
0
function upload()
{
    include_once "classes/Uploader.class.php";
    $uploader = new Uploader("image-data");
    $uploader->saveIn("img");
    $fileUploaded = $uploader->save();
    if ($fileUploaded) {
        $out = "new file uploaded";
    } else {
        $out = "something went wrong";
    }
    return $out;
}
Example #13
0
function upload()
{
    include_once "classes/Uploader.class.php";
    //image-data is the name attribute used in <input type='file' />
    $uploader = new Uploader("image-data");
    $uploader->saveIn("img");
    $fileUploaded = $uploader->save();
    if ($fileUploaded) {
        $out = "new file uploaded";
    } else {
        $out = "something went wrong";
    }
    return $out;
}
Example #14
0
 public function run()
 {
     $uploader = new Uploader();
     if (Yii::app()->request->isPostRequest) {
         //普通上传
         $uploader->initSimple('album')->uploadSimple('simple_file');
         $error = $uploader->getError();
         if (!$error) {
             $data = array('file_name' => $uploader->file_name, 'file_path' => $uploader->file_path, 'file_path_full' => Helper::getFullUrl($uploader->file_path), 'thumb_path' => $uploader->thumb_path, 'thumb_path_full' => Helper::getFullUrl($uploader->thumb_path), 'file_ext' => $uploader->file_ext);
             App::response(200, 'success', $data);
         } else {
             App::response(101, $error);
         }
     }
 }
 /**
  * 文件上传
  */
 public function actionUpload()
 {
     $uploader = new Uploader();
     if (Yii::app()->request->isPostRequest) {
         //断点上传
         $uploader->initSimple('kindeditor')->uploadSimple('kindeditor_file');
         $error = $uploader->getError();
         if (!$error) {
             //返回kindeditor接收的json格式
             exit(CJSON::encode(array('error' => 0, 'url' => Helper::getFullUrl($uploader->file_path))));
         } else {
             exit(CJSON::encode(array('error' => 0, 'message' => $error)));
         }
     }
 }
Example #16
0
 /**
  * 初始化函数,并返回当前类
  * @return Uploader
  */
 public static function init()
 {
     if (!self::$selfObject) {
         self::$selfObject = new Uploader();
     }
     return self::$selfObject;
 }
Example #17
0
 /**
  * 批量操作
  * @throws CHttpException
  */
 public function actionBatch()
 {
     if ($this->method() == 'GET') {
         $command = trim($this->_request->getParam('command'));
         $ids = intval($this->_request->getParam('id'));
     } elseif ($this->method() == 'POST') {
         $command = $this->_request->getPost('command');
         $ids = $this->_request->getPost('id');
     } else {
         throw new CHttpException(404, Yii::t('admin', 'Only POST Or GET'));
     }
     empty($ids) && $this->message('error', Yii::t('admin', 'No Select'));
     switch ($command) {
         case 'attachDelete':
             foreach ((array) $ids as $id) {
                 $uploadModel = Upload::model()->findByPk($id);
                 if ($uploadModel) {
                     Uploader::deleteFile($uploadModel->file_name);
                     $uploadModel->delete();
                 }
             }
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
             break;
     }
     $this->message('success', Yii::t('admin', 'Batch Operate Success'), $this->createUrl('index'));
 }
Example #18
0
 public static function uploadImage()
 {
     $allowFile = array("image/jpeg", "image/png", "image/gif");
     $df = "Ymd-H-i-s";
     $fileName = "TMPIMG" . date($df) . "." . Uploader::getExtension();
     if (!Uploader::getTempFile()) {
         $result['error'] = true;
         $result['message'] = 'Please browse for a file!';
         echo json_encode($result);
         return;
     }
     if (!in_array(Uploader::getType(), $allowFile)) {
         $result['error'] = true;
         $result['message'] = 'Please choose only image file (jpg, png or gif)!';
         echo json_encode($result);
         return;
     }
     if (Uploader::moveUploadFileTo(self::$tmpDir, $fileName)) {
         $result['error'] = false;
         $result['message'] = 'File upload succeeded!';
         $result['image'] = 'assets/upload/tmp/' . $fileName;
         $result['alt'] = $fileName;
     } else {
         $result['error'] = true;
         $result['message'] = 'Fail in moving file upload!';
     }
     echo json_encode($result);
 }
Example #19
0
 public function run()
 {
     $ids = Yii::app()->request->getParam('id');
     $command = Yii::app()->request->getParam('command');
     empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select'));
     if (!is_array($ids)) {
         $ids = array($ids);
     }
     $criteria = new CDbCriteria();
     $criteria->addInCondition('id', $ids);
     switch ($command) {
         case 'delete':
             //删除
             foreach ((array) $ids as $id) {
                 $softModel = Soft::model()->findByPk($id);
                 if ($softModel) {
                     Uploader::deleteFile(ROOT_PATH . $softModel->soft_icon);
                     Uploader::deleteFile(ROOT_PATH . $softModel->soft_file);
                 }
             }
             Soft::model()->deleteAll($criteria);
             break;
         case 'show':
             //显示
             Soft::model()->updateAll(['status' => 'Y'], $criteria);
             break;
         case 'hidden':
             //隐藏
             Soft::model()->updateAll(['status' => 'N'], $criteria);
             break;
         default:
             throw new CHttpException(404, Yii::t('admin', 'Error Operation'));
     }
     $this->controller->message('success', Yii::t('admin', 'Batch Operate Success'));
 }
Example #20
0
function upload()
{
    include_once 'models/Uploader.php';
    $uploader = new Uploader('image_data');
    $uploader->saveIn('img');
    $fileUploaded = $uploader->save();
    if ($fileUploaded) {
        $out = 'new file uploaded';
    } else {
        $out = 'something went wrong';
    }
    $out .= "<pre>";
    $out .= print_r($_FILES, true);
    $out .= "</pre>";
    return $out;
}
Example #21
0
 public function setMaxFileSize($new_size)
 {
     if ($new_size > 0 and $new_size <= Uploader::uploadLimit()) {
         $this->max_file_size = $new_size;
     } else {
         throw new Exception('Invalid file size set');
     }
 }
Example #22
0
 public function run()
 {
     $uploader = new Uploader();
     if (Yii::app()->request->isPostRequest) {
         //开始剪切
         $image = $_POST['file'];
         $uploader->initSimple('avatar');
         $cut_image = $uploader->imageCut($image, array('cut_w' => 100, 'cut_h' => 100, 'pos_x' => $_POST['x'], 'pos_y' => $_POST['y']));
         $error = $uploader->getError();
         if (!$error) {
             $data = array('cut_avatar' => $cut_image);
             App::response(200, '裁剪成功', $data);
         } else {
             App::response(101, $error);
         }
     }
 }
Example #23
0
 public function do_handle()
 {
     /* 抓取远程图片 */
     $list = array();
     if (isset($_POST[$this->fieldName])) {
         $source = $_POST[$this->fieldName];
     } else {
         $source = $_GET[$this->fieldName];
     }
     foreach ($source as $imgUrl) {
         $item = new Uploader($imgUrl, $this->config, "remote");
         $info = $item->getFileInfo();
         array_push($list, array("state" => $info["state"], "url" => $info["url"], "size" => $info["size"], "title" => htmlspecialchars($info["title"]), "original" => htmlspecialchars($info["original"]), "source" => htmlspecialchars($imgUrl)));
     }
     /* 返回抓取数据 */
     return json_encode(array('state' => count($list) ? 'SUCCESS' : 'ERROR', 'list' => $list));
 }
 public static function text($text, $options = array())
 {
     $params = array("timestamp" => time(), "text" => $text);
     foreach (Uploader::$TEXT_PARAMS as $key) {
         $params[$key] = \Cloudinary::option_get($options, $key);
     }
     return Uploader::call_api("text", $params, $options);
 }
Example #25
0
 public function upload()
 {
     if (isset($_FILES)) {
         $project = $_POST['project'];
         $parentDirCrypted = $_POST['parent'];
         $facade = new SystemFacade($project);
         $parent = $facade->decrypt($parentDirCrypted);
         for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
             $fileName = $_FILES['file']['name'][$i];
             $fileTmp = $_FILES['file']['tmp_name'][$i];
             $fileType = $_FILES['file']['type'][$i];
             $fileSize = $_FILES['file']['size'][$i];
             $fileError = $_FILES['file']['error'][$i];
             $uploader = new Uploader($fileName, $fileType, $fileTmp, $fileSize, $fileError);
             if ($uploader->uploadFile()) {
                 $facade->manageFileName($fileName, $parent);
                 if ($facade->createObject($parent, $uploader->getFileName(), $uploader->getRealType(), $uploader->getFileType(), $uploader->getUploadedSource())) {
                     $facade->refreshDirectoryDate($parent);
                 } else {
                     echo "Couldn't save file to database.";
                 }
             } else {
                 echo $uploader->getError();
             }
         }
         echo $facade->makeFileList();
     }
 }
Example #26
0
 /**
  * Test case for getting a files meta data: dimensions, extension, mimetype, etc.
  */
 public function meta()
 {
     $this->testPath = $this->testPath . 'test_dimensions.jpg';
     debug($this->Uploader->dimensions($this->testPath));
     debug(Uploader::mimeType($this->testPath));
     debug(Uploader::ext($this->testPath));
     $this->set('title_for_layout', 'Upload: Meta Data');
     $this->render('single_upload');
 }
 public function imgUpload()
 {
     Vendor('um.Uploader', '', '.class.php');
     $config = array("savePath" => APP_PATH . "Public/Upload/", "maxSize" => 2 * 1024, "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp"));
     $up = new Uploader("upfile", $config);
     $type = $_REQUEST['type'];
     $callback = $_GET['callback'];
     $info = $up->getFileInfo();
     $info['url'] = str_replace(APP_PATH, '', $info['url']);
     /**
      * 返回数据	
      */
     if ($callback) {
         echo '<script>' . $callback . '(' . json_encode($info) . ')</script>';
     } else {
         echo json_encode($info);
     }
 }
 public function run()
 {
     $uploader = new Uploader();
     if (Yii::app()->request->isPostRequest) {
         //断点上传
         $uploader->initResumable('album')->uploadResumable('file');
         $error = $uploader->getError();
         if (!$error) {
             $data = array('file_name' => $uploader->file_name, 'file_path' => $uploader->file_path, 'file_path_full' => Helper::getFullUrl($uploader->file_path), 'file_ext' => $uploader->file_ext);
             App::response(200, 'success', $data);
         } else {
             App::response(101, $error);
         }
     } else {
         //校验已上传的片段
         $uploader->checkExistChunks();
     }
 }
 static function saveImageComplex($base64img, $fname)
 {
     $extension = addslashes($_GET['ext']);
     if ($extension == "jpg") {
         $tipe_ext = "jpeg";
     } else {
         $tipe_ext = $extension;
     }
     //        define('UPLOAD_DIR', '../uploads/');
     $base64img = str_replace('data:image/' . $tipe_ext . ';base64,', '', $base64img);
     $data = base64_decode($base64img);
     $file = _PHOTOPATH . $fname . '.' . $extension;
     file_put_contents($file, $data);
     $dest = _PHOTOPATH . 'thumbnail/' . $fname . '.' . $extension;
     $uploader = new Uploader();
     $params = array('constraint' => array('width' => 200, 'height' => 200));
     $uploader->img_resize($file, $dest, $params);
 }
Example #30
0
 public static function factory($accountType)
 {
     if (Instructor::getName() === $accountType) {
         return new Instructor();
     }
     if (Uploader::getName() === $accountType) {
         return new Uploader();
     }
     return new Student();
 }