Exemple #1
0
 public function upload_head()
 {
     $upfile_path = Tiny::getPath("uploads") . "/head/";
     $upfile_url = preg_replace("|" . APP_URL . "|", '', Tiny::getPath("uploads_url") . "head/", 1);
     //$upfile_url = strtr(Tiny::getPath("uploads_url")."head/",APP_URL,'');
     $upfile = new UploadFile('imgFile', $upfile_path, '500k', '', 'hash', $this->user['id']);
     $upfile->save();
     $info = $upfile->getInfo();
     $result = array();
     if ($info[0]['status'] == 1) {
         $result = array('error' => 0, 'url' => $upfile_url . $info[0]['path']);
         $image_url = $upfile_url . $info[0]['path'];
         $image = new Image();
         $image->suffix = '';
         $image->thumb(APP_ROOT . $image_url, 100, 100);
         $model = new Model('user');
         $model->data(array('head_pic' => $image_url))->where("id=" . $this->user['id'])->update();
         $safebox = Safebox::getInstance();
         $user = $this->user;
         $user['head_pic'] = $image_url;
         $safebox->set('user', $user);
     } else {
         $result = array('error' => 1, 'message' => $info[0]['msg']);
     }
     echo JSON::encode($result);
 }
Exemple #2
0
 function photoshop_upload()
 {
     $file = $_FILES['upfile'];
     if ($file['error'] == 4) {
         $msg = array('error', '请选择文件后再上传!');
         $this->redirect("photoshop", true, array('msg' => $msg));
     } else {
         if ($file['error'] == 1) {
             $msg = array('error', '文件超出了php.ini文件指定大小!');
             $this->redirect("photoshop", true, array('msg' => $msg));
         } else {
             if ($file['size'] > 0) {
                 $key = md5_file($file['tmp_name']);
                 $gallery = new Model('gallery');
                 $img = $gallery->where("`key`='" . $key . "'")->find();
                 echo JS::import('dialog?skin=brief');
                 echo JS::import('dialogtools');
                 if (!$img) {
                     $upfile_path = Tiny::getPath("uploads");
                     $upfile_url = preg_replace("|^" . APP_URL . "|", '', Tiny::getPath("uploads_url"));
                     $upfile = new UploadFile('upfile', $upfile_path, '10m');
                     $upfile->save();
                     $info = $upfile->getInfo();
                     $result = array();
                     if ($info[0]['status'] == 1) {
                         $url = $upfile_url . $info[0]['path'];
                         $key = md5_file($upfile_path . $info[0]['path']);
                         $type = Req::args("type") == null ? 0 : intval(Req::args('type'));
                         $gallery->data(array('key' => $key, 'type' => $type, 'img' => $url))->save();
                         echo "<script>art.dialog.opener.setImg('{$url}');</script>";
                     } else {
                         $msg = array('error', $info[0]['msg']);
                         $this->msg = $msg;
                         $this->redirect("photoshop", false);
                     }
                 } else {
                     $url = $img['img'];
                     echo "<script>art.dialog.opener.setImg('{$url}');</script>";
                 }
             }
         }
     }
     exit;
 }
Exemple #3
0
 public function img_upload()
 {
     $path = APP_ROOT;
     $upf = new UploadFile('imgFile', $path, '2m', 'jpg,jpeg,gif');
     $upf->save();
     $info = $upf->getInfo();
     if ($info[0]['status'] == 1) {
         echo JSON::encode(array('error' => 0, 'url' => $info[0]['path']));
         exit;
     }
 }