【问题标题】:Issue in uploading image file on server using postman in laravel 5.3?在 laravel 5.3 中使用邮递员在服务器上上传图像文件时出现问题?
【发布时间】:2017-01-30 17:38:45
【问题描述】:

我正在使用干预来调整文件大小功能和上传文件。 在控制器中,我只是检查hasFile() 与否。所以,每次我得到“不”的回应,即使我使用邮递员正确发送它。可能是什么问题?

我的路线

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')))){
        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;

  }

【问题讨论】:

  • 执行dd($request->all()) 看看它显示了什么。很可能,photo 不是发布数据的正确名称

标签: php laravel laravel-5.3 intervention


【解决方案1】:

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

Postman Body

Postman Headers

【讨论】:

  • 我明白了。非常感谢 MdRasel Ahmed。
【解决方案2】:

表单标签中的 enctype 属性是什么?如果你上传文件,它应该是这样的:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 2019-06-01
    • 1970-01-01
    • 2020-11-19
    相关资源
    最近更新 更多