Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eddydan's avatar

Laravel - how to use Uppy for image uploading and saving the Image to a Folder in my server

I have this project with image uploading and I use Uppy for it. The uploaded image are store in an hidden form input as show below;

<input name="photos[]" type="hidden" value="{"id":"https://tusd.tusdemo.net/files/2b1b4528de1ac8c845f98d5046eb8e5b+Il_EWbeYMoMss0amHhCiziz6ekGHOLOmemYMHngbiDuos6PbTMAZM_YAeYNAfTGZaLA2b6UOpEu1u.svbMlFbjIktx6aykEP_K.kXwt7nnbCF2kK0oCs1Jg4YAWCJaZR","storage":"cache","metadata":{"filename":"dan1.jpg","size":109472,"mime_type":"image/jpeg"}}">

I try to get the image from the url on the hidden form input but I am having issues to get the file.. Here below my Controller code:

$imageUrls = [];

    foreach ($request->photos as $image) {
         
            $url = $image;
            $contents = file_get_contents($url);
            $imageName = time().'-'.uniqid().'.'.$contents->getClientOriginalExtension();
        $resize_full_image->save('assets/uploads/profile_photo' .'/'. $imageName);

When I run the code I get this error;

error "An error occurred while creating product: file_get_contents({"id":"https://tusd.tusdemo.net/files/5f928ca7ebb25d77d0649a4be5aadfb4+1QMwIHU1bSwQ_rk61mPVZRUBfFpb25iUlxzLDUT6lkVju0V3PflOudWpur0in8Ehknw5bqeuXnnIUFY_vfd8YXCXHwGYmBWPg3D2LTaIkjwIkAQj4KX1DkSeERD.QT9H","storage":"cache","metadata":%7B"filename":"dan1.jpg","size":109472,"mime_type":"image/jpeg"%7D}): Failed to open stream: No such file or directory"

0 likes
3 replies
Snapey's avatar

you need to json_decode the input field before trying to use its attributes

eddydan's avatar

@Snapey error "An error occurred while creating product: Malformed UTF-8 characters, possibly incorrectly encoded" the error message im getting

Please or to participate in this conversation.