Hi everyone,
Sometimes I don’t really understand how PHP handles its queue jobs…
I have a hook that creates a video thumbnail when I upload a video file :
'file.create:after' => function (Kirby\Cms\File $file) {
if (option('cloudinary', false) === true && $file->type() == 'video') {
$url = str_replace('q_auto:best,f_mp4', 'c_scale,f_jpg,q_100,w_400,so_0', $file->url());
$imagedata = file_get_contents($url);
F::write($file->parent()->root() . '/' . $file->filename() . '.jpg', $imagedata);
}
},
It works but I ran into an error inside the panel and the file is not selected in the file field where I uploaded the file.
array_key_exists(): Argument #2 ($array) must be of type array, Kirby\Cms\Field given
I have the same problem if I try to upload it in a files section.
Any clues ?
Thanks
texnixe
January 11, 2022, 11:31am
2
tristantbg:
array_key_exists
Is there more information in the browser console or in your php error logs?
Hi @texnixe !
I got this :
{"status":"error","message":"array_key_exists(): Argument #2 ($array) must be of type array, Kirby\\Cms\\Field given","code":500,"key":null,"details":[]}
No Apache error on the server…
Is it because my video file name is :
video.mp4
And my thumbnail file name is :
video.mp4.jpg
???
Maybe Kirby thinks the file already exists at upload ?
texnixe
January 11, 2022, 12:52pm
5
Well, the Apache error log is not interesting, but the PHP error log to get a stack trace of the error.
This doesn’t work either (to prevent same filename issue) :
if (option('cloudinary', false) === true && $file->type() == 'video') {
$url = str_replace('q_auto:best,f_mp4', 'c_scale,f_jpg,q_100,w_400,so_0', $file->url());
$imagedata = file_get_contents($url);
F::write($file->parent()->root() . '/' . F::name($file->filename()) . '-thumbnail.jpg', $imagedata);
}
Found the problem 1 year later.
It was due to a plugin with a hook on uploaded files that couldn’t handle video files and was missing a condition to filter files only of type “image” !