/** * 上传私有方法 * @method upload * @param string $path 上传目录 * @param integer $size 文件大小 * @param array $exts 允许格式 * @return array 成功返回数据,失败返回false */ private function upload($path = './Uploads/', $size = 3145728, $exts = array('jpg', 'gif', 'png', 'jpeg')) { $upload = new Upload(); $upload->maxSize = $size; $upload->exts = $exts; $subName = array('date', 'Ymd'); if (!file_exists($path)) { mkdir($path, 0777, true); } $upload->rootPath = $path; $upload->subName = $subName; $info = $upload->upload(); return $info; }
/** * 上传文件方法 * @method upload * @param integer $size 允许上传文件大小 * @param array $exts 允许上传文件格式 * @return string 文件路径 */ private function upload($size = 3145728, $exts = array('jpg', 'gif', 'png', 'jpeg')) { $upload = new Upload(); $upload->maxSize = $size; $upload->exts = $exts; $path = './Uploads/'; $subName = array('date', 'Ymd'); if (!file_exists($path)) { mkdir($path, 0777, true); } $upload->rootPath = $path; $upload->subName = $subName; $info = $upload->upload(); if (is_array($info)) { $keys = array_keys($info); $info = $path . $info[$keys[0]]['savepath'] . $info[$keys[0]]['savename']; } return $info; }
public function AjaxUpload() { $upload = new Upload(); $upload->maxSize = 3145728; $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); $upload->savePath = ''; $rootPath = './Uploads/'; $upload->rootPath = $rootPath; $info = $upload->upload(); if ($info) { $fileinfo = array_shift($info); $filename = $rootPath . $fileinfo['savepath'] . $fileinfo['savename']; $data['status'] = 1; $data['info'] = $filename; } else { $data['status'] = 0; $data['info'] = $upload->getError(); } die(json_encode($data)); }
public function upload() { $upload = new Upload(); // 实例化上传类 $upload->maxSize = 3145728; // 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型 $info = $upload->upload($_FILES); $_info = array(); if ($info) { foreach ($info as $_k => $_v) { array_push($_info, $_v); } $filename = './Uploads/' . $_info[0]['savepath'] . $_info[0]['savename']; $result['status'] = 1; $result['info'] = $filename; } else { $result['status'] = 0; $result['info'] = $upload->getError(); } die(json_encode($result)); }