kendrick's avatar

How to get a closer look inside an image upload-process?

I am using the Intervention Image Package for uploading images.

E.g.:

$this->validate($request, [
    'image' => 'max:800',
]);

if($request->hasFile('image')){

    $user = Auth::user();

    $image   = $request->file('image');
    $filename = time() . '.' . $image->getClientOriginalExtension();
    $location = public_path('uploads/'. $filename );
    Image::make($image)->resize(300,300)->save($location);
            
    $user->image = $filename;
    $user->save();
}

This is only touching the surface. How can I get a closer look inside the process, in terms of

(1) validation,

(2) upload communication and

(3) error display, but also with respect to maybe

(4) previewing the chosen images, before uploading them?

Really looking forward for your advice, thank you

0 likes
1 reply
aurawindsurfing's avatar

The easiest would be to put this image into a /temp folder, do with it what you have to do and then move it to the final location.

Validation is done like this:

'photo' => 'mimes:jpeg,bmp,png'

Upload and error - possibly simple try - catch block?

Preview the file from /temp folder.

Please or to participate in this conversation.