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

ashahdblu's avatar

Laravel /Docker /Spatie Media Library -- Could not load image at path

Hi guys i have an issue with the deployment related to spatie media library package i dockorized the app and spined the container in aws ec2 it works fine but the image upload is throwing this err

Could not load image at path /usr/src/app/storage/media-library/temp/TbOvHHHaULQPYqnuOdXT7nlj4kpyzoUp/UAT5X2Agm6EQWbkYZcxEaWLGYMEfviu0thumbnail.jpg

i thought it was an permission issue in the docker container i added those lines to my docker file

RUN mkdir -p /usr/src/app/storage/media-library/temp RUN chmod -R 775 /usr/src/app/storage/media-library/temp RUN chown -R www-data:www-data /usr/src/app/storage/media-library/temp

but the issue still exist

0 likes
2 replies
oleksii_b's avatar

I had the same issue and it appeared that my php didn't support webp format. After enabling webp in php gd this problem disappeared.

Try to debug your path like this:

$path = 'your_path';
$handle = fopen($path, 'r');
$contents = fread($handle, filesize($path));
fclose($handle);

// in most cases exception will be trown here but in original code this line is suppressed with @ $image = imagecreatefromstring($contents);

MedtheVorg's avatar

I faced the same issue and what solved it was that I changed the cpanel php current version from 8.3 to 8.2 ( and activated imagick extention because it got disabled after the switch) which what my project was using originaly.

Please or to participate in this conversation.