1

I am using intervention for file resize functionality and for file uploading. In controller I am just checking hasFile() or not. so, everytime I got "no" in response even if I am sending it properly using postman. what can be the issue ?

my route

Route::post('contact/image/upload',[  
  'as'=> 'intervention.postresizeimage',
  'uses'=>'contactController@upload_image'
]);

code in controller

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
  • 1
    Do dd($request->all()) and see what it shows. Most probably, photo is not the correct name of the posted data Commented Jan 30, 2017 at 7:11

2 Answers 2

5

I also think so photo is not correct name for the posted data. You may see the given images of Postman:

Postman Body

Postman Headers

Sign up to request clarification or add additional context in comments.

1 Comment

I got it . Thanks a ton MdRasel Ahmed.
1

What's your enctype attribute in the form tag? It should look like this if you upload files:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.