I noticed today that when I try to upload images on the server, there is an error message in many, but not all of my projects as follows:
This message appears when I try to upload an image by any means (file picker or drag&drop) independent from the image file (I tried several), but only on the server. I have never seen this locally for the exactly same projects with exactly the same code. It’s not even happening consistently in all projects.
Does anyone have a clue where this might come from?
It’s happening for PHP versions 7.4, 8.0 and 8.1 and Kirby version 3.6.0, 3.6.1 and 3.6.2. When the error is there, I couldn’t find a combination, where the error disappears. In another project, file uploads are working fine with the same combinations.
I also checked the htaccess files and there is nothing suspicious. In fact I didn’t adjust these for long times.
The error may be there for a long time as I hardly use the panel online at all.
Thanks in advance!
Can you find a stack trace in the browser console? Obviously the url passed to the HTML::img() method is null which it may not be if the file exists. I wonder if this is some sort of permission issue, but that’s just groping around.
Thanks for the hint. Indeed there is an internal server error (500), when I do the upload. So I thought it might really be a permission issue, but that is not the case (it seems). Folder permissions are set to 755 and I even tried 777 for testing, but the internal server error remained.
I can see that the file is uploaded to a /tmp folder on the server from where it should probably be moved to the target folder after successful upload. But this doesn’t happen. So this does point towards a permissions error in the target folder, doesn’t it? But I thought I had excluded that with the previous test.
OK, I found the problem. It was due to one of my plugins.
There I echoed the
$upload variable, which is of type
Kirby\Filesystem\File and breaks when echoing (I must have introduced this error when adjusting the hooks for Kirby 3.6+). The problem was solved by echoing
$upload->filename() instead. Strangely, there was no PHP error logged in this case while other PHP errors are logged. So it took me some time.
Thanks for the support @texnixe as always!