/**
* @param savepath :例子'./Public/Uploads/ProjectCate/'
* @param $maxSize :单个文件大小最大限制 单位字节
* @return array
* status: 200 成功,400失败;
* message: 提示信息
* data: 保存的图片信息
*/
function upload_img($savepath, $maxSize = 301309)
{
$result = array('status' => 400, 'message' => '非法操作!', 'data' => array());
import('ORG.Net.UploadFile');
$upload = new UploadFile();
$upload->maxSize = $maxSize;
$upload->allowExts = array('jpg', 'jpeg', 'png');
$upload->allowTypes = array('image/jpeg', 'image/gif', 'image/bmp', 'image/png', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
// #TODO 限定图片类型
$upload->savePath = $savepath;// 设置附件上传目录
$upload->saveRule = 'uniqid';
if (!$upload->upload()) {// 上传错误提示错误信息
$result['message'] = $upload->getErrorMsg();
if ($result['message'] == '上传文件大小不符!') {
$result['message'] = '图片尺寸需小于300K';
}
$result['status'] = 500;
return $result;
} else {// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
$result['status'] = 200;
$result['message'] = '上传成功!';
$result['data'] = $info;
}
return $result;
}