SaMeEr
SaMeEr

Reputation: 381

Issue in laravel image upload using intervention?

I have written a code to upload a Image using intervention. but Image didn't find in respective directory. I am uploading a image using postman form-data. even a message comes after upload which is I am returning "uploaded".

Here is my route

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

controller - contactController.php

<?php

    namespace App\Http\Controllers;

    use Illuminate\Support\Facades\File;
    use Illuminate\Http\Request;
    use App\Http\Traits\queryBuilderTrait;
    use App\Http\Traits\imageUploadTrait;
    use App\Http\Requests;
    use DB;
    use Image;
    use App\Contact;
    use \Carbon\Carbon;
    use App\User;
    use App\Communication_link;
    use App\Contact_communication;
    use App\addId;

    class contactController extends Controller
    {
        use queryBuilderTrait; 
        use imageUploadTrait;
        public $response;

        public function upload_image(Request $request) {
            $this->validate($request, [
                'photo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:1024',
            ]);

            $photo = $request->file('photo');
            $imagename = $photo->getClientOriginalExtension(); 

            $destinationPath = public_path('thumbnail_images');
            $thumb_img = Image::make($photo->getRealPath())->resize(100, 100);
            $thumb_img->save($destinationPath.'/'.$imagename,80);

            $destinationPath = public_path('normal_images');
            $photo->move($destinationPath, $imagename);
            return "uploaded";
      }
}

Upvotes: 1

Views: 677

Answers (1)

Advaith
Advaith

Reputation: 2580

Try doing like this --

public function upload_image(Request $request) {
    $this->validate($request, [
        'photo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:1024',
    ]);

    $image = $request->file('photo');
    $filename = time() . '.' . $image->getClientOriginalExtension();
    $location = public_path('images/' . $filename);
    Image::make($image)->resize(800, 600)->save($location);

    return "uploaded";
}

Upvotes: 1

Related Questions