...
|
...
|
@@ -236,33 +236,58 @@ class BusinessController extends Controller |
|
|
* @author panhaowen
|
|
|
* @url /portal/business/postImage
|
|
|
* @method POST
|
|
|
* @param name:image[] type:array require:1 desc:图片资源文件
|
|
|
* @param name:image type:string require:1 desc:图片资源文件
|
|
|
*/
|
|
|
public function postImage()
|
|
|
{
|
|
|
$file = Request()->file('image');
|
|
|
if (!$file) {
|
|
|
$this->error('上传失败1');
|
|
|
}
|
|
|
|
|
|
|
|
|
$file = $this->request->file('file');
|
|
|
// 移动到框架应用根目录/public/upload/ 目录下
|
|
|
$info=[];
|
|
|
foreach ($file as $v) {
|
|
|
$a = $v->move(ROOT_PATH . 'public' . DS . 'upload' . DS . 'image');
|
|
|
$image = cmf_get_image_preview_url('image' . DS . $a->getSaveName()); //返给前台可读取的url路径
|
|
|
array_push($info,$image);
|
|
|
$info = $file->validate([
|
|
|
/*'size' => 15678,*/
|
|
|
'ext' => 'jpg,png,gif'
|
|
|
]);
|
|
|
$fileMd5 = $info->md5();
|
|
|
$fileSha1 = $info->sha1();
|
|
|
|
|
|
$findFile = Db::name("asset")->where('file_md5', $fileMd5)->where('file_sha1', $fileSha1)->find();
|
|
|
|
|
|
if (!empty($findFile)) {
|
|
|
$this->success("上传成功!", ['url' => cmf_get_asset_url($findFile['file_path']), 'filename' => $findFile['filename']]);
|
|
|
}
|
|
|
if ($info) { // 成功上传后 获取上传信息
|
|
|
// 输出 jpg
|
|
|
// echo $info->getExtension();
|
|
|
// 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
|
|
|
// echo $info->getSaveName();
|
|
|
// 输出 42a79759f284b767dfcb2a0197904287.jpg
|
|
|
//echo $info->getFilename();
|
|
|
// $image = cmf_get_image_preview_url('image' . DS . $info->getSaveName()); //返给前台可读取的url路径
|
|
|
$this->success('图片上传成功',$info);
|
|
|
$info = $info->move(ROOT_PATH . 'public' . DS . 'upload');
|
|
|
if ($info) {
|
|
|
$saveName = $info->getSaveName();
|
|
|
$originalName = $info->getInfo('name');//name,type,size
|
|
|
$fileSize = $info->getInfo('size');
|
|
|
$suffix = $info->getExtension();
|
|
|
|
|
|
$fileKey = $fileMd5 . md5($fileSha1);
|
|
|
|
|
|
$userId = $this->getUser()['user_id'];
|
|
|
Db::name('asset')->insert([
|
|
|
'user_id' => $userId,
|
|
|
'file_key' => $fileKey,
|
|
|
'filename' => $originalName,
|
|
|
'file_size' => $fileSize,
|
|
|
'file_path' => cmf_get_asset_url($saveName),
|
|
|
'file_md5' => $fileMd5,
|
|
|
'file_sha1' => $fileSha1,
|
|
|
'create_time' => time(),
|
|
|
'suffix' => $suffix
|
|
|
]);
|
|
|
|
|
|
// $storage = cmf_get_option('storage');
|
|
|
|
|
|
// if (isset($storage['type'])&&$storage['type']=='Qiniu') {
|
|
|
// $this->uploadToQiniu($saveName);
|
|
|
// }
|
|
|
|
|
|
$this->success("上传成功!", ['url' => cmf_get_asset_url($saveName), 'filename' => $originalName]);
|
|
|
} else {
|
|
|
// 上传失败获取错误信息
|
|
|
$this->error('上传失败2');
|
|
|
$this->error($file->getError());
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|