2017-01-30 66 views
1

我正在使用干预文件大小调整功能和文件上传。 在控制器中,我只是检查hasFile()或不。所以,即使我使用邮递员正确发送邮件,每次我都会收到“不”的回复。可能是什么问题?使用laravel 5.3中的邮递员上传服务器上的图像文件问题?

我的路线

Route::post('contact/image/upload',[ 
    'as'=> 'intervention.postresizeimage', 
    'uses'=>'[email protected]_image' 
]); 

代码控制器

public function upload_image(Request $request){ 

     if((preg_match("/^[789]\d{9}$/", $request->header('UID')))){ 
     if($request->hasFile('photo')) 
      return "yes"; 
     else 
      return "no"; 


     $photo = $request->file('photo'); 
     $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; 

    } 
+1

做'DD($请求 - >所有())',看看它显示。最有可能的是,'photo'不是发布数据的正确名称 – baig772

回答

4

我也是这么认为的照片不是为发布的数据正确的名称。 您可能会看到邮递员给定的图像:

Postman Body

Postman Headers

+0

我明白了。谢谢一吨MdRasel艾哈迈德。 – SaMeEr

1

什么形式标记你的enctype属性?它应该是这样,如果你上传的文件:

<form method="post" enctype="multipart/form-data">