Error 500 – Failed to write image to file

i fail to load images from any page of the my website.

in the console i get a 500 error, and i see that kirby tries to load the file from the media folder but the folder is empty

in the php error log i read:
Failed to write image to file: /path../cesar-rincon-xhvpwcr5grq-unsplash-1-1-900x.avif in /path/vendor/claviska/simpleimage/src/claviska/SimpleImage.php:508

when i access the panel i see all the files
and i’m using a public folder setup

i guess is a permission problem… any idea where to fix it?

and is weird because on my server i see the file…

i was running 4.0.0-rc.2, downgrading to kirby 3.9.8 everything works fine.

is it a bug or i forgot to update something?

Tested an .avif file in rc.2 and had no problems. Can you share your template/snippet where you load the image, because this error appears if the toFile function fails

Here you say the folder is empty

Here you show that the folder is not empty.

I’m a bit confused.

Did you delete the media folder when you updated to Kirby 4?

your are right, sorry for the confusion:

the files in the screenshots were generated in my local environment where everything is working–i uploaded them by mistake.

when on the server it only generates .json file into the /.jobs folder
but even with the media folders from my local environment was not loading any file.

there is something wrong in how i load the images (but i can’t understand why only on the server?)
i use this template

<picture>
  <?php foreach (['avif', 'webp', 'jpg'] as $format) : ?>

    <?php
    $srcset = [
      '300w'  => ['width' => 300, 'format' => $format],
      '600w'  => ['width' => 600, 'format' => $format],
      '900w'  => ['width' => 900, 'format' => $format],
      '1200w' => ['width' => 1200, 'format' => $format],
      '1800w' => ['width' => 1800, 'format' => $format],
    ];
    ?>

    <?php if ($format != 'jpg') : ?>
      <source type="image/<?= $format ?> " sizes="<?= $sizes ?? '' ?>" srcset="<?= $image->srcset($srcset) ?>">
    <?php else : ?>
      <img class="<?= $class ?? '' ?>" src="<?= $image->srcset($srcset) ?>" sizes="<?= $sizes ?? '' ?>" alt="<?= $alt ?? '' ?>">
    <?php endif ?>
  <?php endforeach; ?>
</picture>

and passing it with a snippet:
<?php snippet('blocks/picture', ['image' => $file, 'sizes' => '60vw'])?>

i made a test with a norm tag and everything works fine

this is the test website with both images next to each other: https://test.maat.xyz/

if you refresh a couple of times you see briefly the image on the left

So this error message comes from SimpleImage, does the version of the GD library on your server even support .avif?

yes, avif is supported – i’m running other websites with the same configuration
the only difference is that they are on kirby 3.9.8 the test i’m showing runs on kirby 4 rc.3

still could not solve the issue, also tried to use the new rc4…
has anyone idea of what the problem and possible solutions could be?

If I put everything together what has been written before, it seems that PHP could not write the file, because it is already there and has permissions which inhibits the server process from writing to the same file. This could happen if you upload a file with a different kind of access, lets say FTP or SSH and this process creates file with its own user, but this user is different from the PHP process user.

So, you need to check if the file which is already there, has got the correct permissions which the PHP process can overwrite.

thanks @Adspectus for the insight
i don’t know much about file permissions as this has never happened before – but i will look into it!

hey @Adspectus, i’ve changed all files and folders permissions to 644 and 755 with:

find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

and now instead of getting a error 500 i get a 404, the images cannot be found

kirby does not generate any file in the media folder, just a .jobs folder and inside .json files for the files it should create:

example:
media/.jobs/cesar-rincon-xhvpwcr5grq-unsplash-1-1-300x.avif.json

{"width":300,"format":"avif","filename":"cesar-rincon-xhvpwcr5grq-unsplash-1-1.jpg"}

a part from that the website is able to load css and js files from public/assets
my structure is:

content
kirby
public
  - assets
  - media
site
src
storage
vendor

any ideas?
many thanks!

If the folder permissions had been wrong, Kirby wouldn’t have been able to write the jobs files to the folder.

Do you run into this issue even if you remove avif from the array?

if i remove avif i get an error on webp
but actually now i get 404 on all files (but css and js are being loaded)

and i also get a 404 when trying to access the panel.

locally everything works perfectly…