Dear Kirbys
I am following this cookbook Forms with attachments | Kirby CMS
and everything works fine.
Now I want to change the allowed upload file type to a video (mov, mp4).
However, when selecting a .mov or mp4 file, the file processing does not work anymore.
The file error code is “1”, the file “type” is not detecting that it contains “video”, and I am lacking of debugging skills within controllers.
See the relevant part in the applications controller
// loop through uploads and check if they are valid
foreach ($uploads as $upload) {
// make sure the user uploads at least one file
if ($upload['error'] === 4) {
$alerts[] = 'You have to attach at least one file';
// make sure there are no other errors
} elseif ($upload['error'] !== 0) {
// => here the error is always "1" !
$alerts[] = 'The file could not be uploaded';
// make sure the file is not larger than 10MB…
} elseif ($upload['size'] > 10000000) {
$alerts[] = $upload['name'] . ' is larger than 10 MB';
// …and the file is a video (e.g. mp4)
} elseif ($upload['type'] !== 'video/mp4') {
$alerts[] = $upload['name'] . ' is not a MP4';
// all valid, try to rename the temporary file
} else {
$name = $upload['tmp_name'];
$tmpName = pathinfo($name);
// sanitize the original filename
$filename = $tmpName['dirname'] . '/' . F::safeName($upload['name']);
if (rename($upload['tmp_name'], $filename)) {
$name = $filename;
}
// add the files to the attachments array
$attachments[] = $name;
}
}
Any help is highly appreciated.
Thanks a lot.