Esempio n. 1
0
 /**
  * 上传图片的方法
  * @return [type] [description]
  */
 public function upload()
 {
     $up = new fileupload();
     //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成)
     $up->set("path", $this->imagedir);
     $up->set("maxsize", 2000000);
     $up->set("allowtype", array("gif", "png", "jpg", "jpeg"));
     $up->set("israndname", true);
     //使用对象中的upload方法, 就可以上传文件, 方法需要传一个上传表单的名子 pic, 如果成功返回true, 失败返回false
     if ($up->upload("pic")) {
         $data['imagename'] = $up->getoriginname();
         $data['imageid'] = $up->getFileName();
         $data['imageurl'] = $this->imagebaseurl . $data['imageid'];
         $this->res->setdata($data);
         $this->res->echores();
     } else {
         //获取上传失败以后的错误提示
         $this->res->seterr("4001", $up->getErrorMsg());
         $this->res->echores();
         ///Users/baidu/data/devtools/imagetmp
     }
 }