|
@@ -10,27 +10,46 @@ class UploadController extends Controller
|
|
{
|
|
{
|
|
public function uploadImage(Request $request)
|
|
public function uploadImage(Request $request)
|
|
{
|
|
{
|
|
- if($request->hasFile('image') && $request->file('image')->isValid()){
|
|
|
|
- $path = $request->get('path') ? $request->get('path').'/' : date('Ym').'/';
|
|
|
|
- //获取文件的原文件名 包括扩展名
|
|
|
|
-// $yuanname= $request->file('image')->getClientOriginalName();
|
|
|
|
-// //获取文件的扩展名
|
|
|
|
- $kuoname=$request->file('image')->getClientOriginalExtension();
|
|
|
|
|
|
+ $files = $request->file('image');
|
|
|
|
+ Log::debug('files:'.json_encode($files));
|
|
|
|
+ $fileCount = count($files);
|
|
|
|
+ $urls = [];
|
|
|
|
+ for($i=0;$i<$fileCount;$i++){
|
|
|
|
+ $kuoname=$files[$i]->getClientOriginalExtension();
|
|
// //获取文件的类型
|
|
// //获取文件的类型
|
|
// $type=$request->file('image')->getClientMimeType();
|
|
// $type=$request->file('image')->getClientMimeType();
|
|
// //获取文件的绝对路径,但是获取到的在本地不能打开
|
|
// //获取文件的绝对路径,但是获取到的在本地不能打开
|
|
- $filePath=$request->file('image')->getRealPath();
|
|
|
|
|
|
+ $filePath=$files[$i]->getRealPath();
|
|
//要保存的文件名 时间+扩展名
|
|
//要保存的文件名 时间+扩展名
|
|
$filename=time() . '_' . uniqid() .'.'.$kuoname;
|
|
$filename=time() . '_' . uniqid() .'.'.$kuoname;
|
|
- $imageUrl = Storage::put($path.$filename, file_get_contents($filePath));
|
|
|
|
|
|
+ $imageUrl = Storage::put($filename, file_get_contents($filePath));
|
|
Log::debug('upload_url:'.$imageUrl);
|
|
Log::debug('upload_url:'.$imageUrl);
|
|
- if($imageUrl){
|
|
|
|
- return $this->jsonSuccess(['url' => $path.$filename]);
|
|
|
|
- }else{
|
|
|
|
- return $this->jsonError('图片上传失败,请重试');
|
|
|
|
- }
|
|
|
|
|
|
+ array_push($urls,$imageUrl);
|
|
|
|
+ }
|
|
|
|
+ if($urls){
|
|
|
|
+ return $this->jsonSuccess(['url' => $filename]);
|
|
}else{
|
|
}else{
|
|
- return $this->jsonError('仅支持图片上传,请重试');
|
|
|
|
|
|
+ return $this->jsonError('图片上传失败,请重试');
|
|
}
|
|
}
|
|
|
|
+// if($request->hasFile('image') && $request->file('image')->isValid()){
|
|
|
|
+// $path = $request->get('path') ? $request->get('path').'/' : date('Ym').'/';
|
|
|
|
+//// //获取文件的扩展名
|
|
|
|
+// $kuoname=$request->file('image')->getClientOriginalExtension();
|
|
|
|
+//// //获取文件的类型
|
|
|
|
+//// $type=$request->file('image')->getClientMimeType();
|
|
|
|
+//// //获取文件的绝对路径,但是获取到的在本地不能打开
|
|
|
|
+// $filePath=$request->file('image')->getRealPath();
|
|
|
|
+// //要保存的文件名 时间+扩展名
|
|
|
|
+// $filename=time() . '_' . uniqid() .'.'.$kuoname;
|
|
|
|
+// $imageUrl = Storage::put($path.$filename, file_get_contents($filePath));
|
|
|
|
+// Log::debug('upload_url:'.$imageUrl);
|
|
|
|
+// if($imageUrl){
|
|
|
|
+// return $this->jsonSuccess(['url' => $path.$filename]);
|
|
|
|
+// }else{
|
|
|
|
+// return $this->jsonError('图片上传失败,请重试');
|
|
|
|
+// }
|
|
|
|
+// }else{
|
|
|
|
+// return $this->jsonError('仅支持图片上传,请重试');
|
|
|
|
+// }
|
|
}
|
|
}
|
|
}
|
|
}
|