case 'uploadimage': $config = array("pathFormat" => '/Uploads/Img/' . $_GET['Type'] . '/' . date('Y', time()) . '/' . date('m', time()) . '/' . date('d', time()) . '/' . randNums() . $imginfo['0'] . 'x' . $imginfo['1'], "maxSize" => $CONFIG['imageMaxSize'], "allowFiles" => $CONFIG['imageAllowFiles']); $fieldName = $CONFIG['imageFieldName']; break; case 'uploadscrawl': $config = array("pathFormat" => $CONFIG['scrawlPathFormat'], "maxSize" => $CONFIG['scrawlMaxSize'], "allowFiles" => $CONFIG['scrawlAllowFiles'], "oriName" => "scrawl.png"); $fieldName = $CONFIG['scrawlFieldName']; $base64 = "base64"; break; case 'uploadvideo': $config = array("pathFormat" => '/Uploads/Video/' . $_GET['Type'] . '/' . date('Y', time()) . '/' . date('m', time()) . '/' . date('d', time()) . '/' . randNums(), "maxSize" => $CONFIG['videoMaxSize'], "allowFiles" => $CONFIG['videoAllowFiles']); $fieldName = $CONFIG['videoFieldName']; break; case 'uploadfile': default: $config = array("pathFormat" => '/Uploads/File/' . $_GET['Type'] . '/' . date('Y', time()) . '/' . date('m', time()) . '/' . date('d', time()) . '/' . randNums(), "maxSize" => $CONFIG['fileMaxSize'], "allowFiles" => $CONFIG['fileAllowFiles']); $fieldName = $CONFIG['fileFieldName']; break; } /* 生成上传实例对象并完成上传 */ $up = new Uploader($fieldName, $config, $base64); /** * 得到上传文件所对应的各个参数,数组结构 * array( * "state" => "", //上传状态,上传成功时必须返回"SUCCESS" * "url" => "", //返回的地址 * "title" => "", //新文件名 * "original" => "", //原始文件名 * "type" => "" //文件类型 * "size" => "", //文件大小 * )
/** * [uploadImg description] * @return [type] [description] */ public function uploadFile() { $fileType = I('get.fileType'); $type = I('get.type'); import('ORG.Net.UploadFile'); $upload = new UploadFile(); // 实例化上传类 $randNums = strtoupper(randNums('12', 'CHAR')); $path = $fileType . '/' . $type . '/' . date('Y', time()) . '/' . date('m', time()) . '/' . date('d', time()) . '/'; switch ($fileType) { case 'Img': $imginfo = getimagesize($_FILES['Filedata']['tmp_name']); $width = $imginfo['0']; $height = $imginfo['1']; $exts = array('jpg', 'gif', 'png', 'jpeg'); $saveName = $randNums . $width . 'x' . $height; $upload->thumb = true; $upload->thumbMaxWidth = '200'; $upload->thumbMaxHeight = '150'; $upload->thumbPath = ''; $upload->thumbFile = 'thumb_' . $randNums . '_200x150'; $upload->thumbRemoveOrigin = true; break; case 'Music': $exts = array('mp3'); $saveName = $randNums; break; } $upload->maxSize = 3145728; // 设置附件上传大小 $upload->allowExts = $exts; // 设置附件上传类型 $upload->savePath = './Uploads/' . $path; // 设置附件上传目录 if (is_dir($upload->savePath) == false) { mkdir($upload->savePath, '0755', true); } $upload->saveRule = $saveName; if (!$upload->upload()) { // 上传错误提示错误信息 $data['valid'] = false; $data['state'] = $upload->getErrorMsg(); } else { // 上传成功 获取上传文件信息 $data['valid'] = true; $data['state'] = 'SUCCESS'; $info = $upload->getUploadFileInfo(); $data['url'] = '/Uploads/' . $path . 'thumb_' . $randNums . '_200x150' . '.' . $info['0']['extension']; } $this->ajaxReturn($data); }