【发布时间】:2017-02-02 15:11:05
【问题描述】:
我正在对图像上传功能使用干预,但是当我尝试从邮递员上传带有标题中“内容类型:多部分/表单数据”的图像时,它会显示上述错误,但如果我删除内容类型标题然后它工作正常。我添加了邮递员的图像。
我的路线
Route::post('contact/image/upload',['as'=>'intervention.postresizeimage','uses'=>'contactController@upload_image']);
控制器中的代码
public function upload_image(Request $request){
if((preg_match("/^[789]\d{9}$/", $request->header('UID')))){
$photo = $request->file('image');
$imagename = time().'.'.$photo->getClientOriginalExtension();
$destinationPath_thumb = storage_path('images/thumbnail_images');
$thumb_img = Image::make($photo->getRealPath())->resize(100, 100);
$thumb_img->save($destinationPath_thumb.'/'.$imagename,80);
$destinationPath_medium = storage_path('images/medium_images');
$medium_img = Image::make($photo->getRealPath())->resize(500, 500);
$medium_img->save($destinationPath_medium.'/'.$imagename,80);
$destinationPath_original = storage_path('images/original_images');
$photo->move($destinationPath_original, $imagename);
$user = \App\User::select(['inst_id'])->where('mobile','=',$request->header('UID'))->first();
$update_img = \App\Contact::where([['id','=',$request->ID],['inst_id','=',$user->inst_id]])->update(['image'=>$imagename]);
if($update_img)
$response = response()->json(['data'=>[], 'error'=>0, 'error_msg'=>'', 'message'=>'Profile updated']);
else
$response = response()->json(['data'=>[], 'error'=>1, 'error_msg'=>'some went wrong', 'message'=>'Please try again']);
}
else
$response = response()->json(['data'=>[], 'error'=>1, 'error_msg'=>'wrong mobile in UID header','message'=>'wrong mobile no. in header']);
return $response;
}
【问题讨论】:
-
您的照片尚未上传。尝试用这张 $photo[0] 代替照片
-
我应该在哪里改变这个?
-
尝试打印 $photo 变量并检查值。还要检查您的表单,它应该是 enctype="multipart/form-data"。
-
@shafiq 我使用 laravel 作为 API 那么如何检查这个 enctype 呢?
-
我尝试使用 dd($photo) 打印 $photo,所以我得到了空数组作为响应。
标签: laravel laravel-5 laravel-5.3 postman intervention