I have an file upload form, and I want to use validator.
$roles = array(
'title' => 'required|max:128',
'description' => 'required|max:2800',
'picture' => 'mimes:jpeg,bmp,png'
);
My problem is, if I try to upload a picture, I get this error: finfo::finfo(): Failed to load magic database at ''
. The $_SERVER['MAGIC']
is set to /usr/share/misc/magic
... So I don't know why throw this error. But if I comment out the picture validation line, and I select a photo is the form, I also get an error: Serialization of 'Symfony\\Component\\HttpFoundation\\File\\UploadedFile' is not allowed
.
Can anybody tell me what should I do?
$finfo = new finfo(FILEINFO_MIME_TYPE);
$filename = public_path() . '/images/test.png';
var_dump($finfo->file($filename));
It works good string(9) "image/png"
. But in the validation still bad.
Laravel uses finfo for file validation and finfo
needs magic_file
name of a magic database file, usually something like /path/to/magic.mime. In your php.ini
make sure you have something like this available and it points qo the right resource
[mime_magic]
mime_magic.magicfile = "D:\xampp\php\extras\magic.mime"
This is the path for the file in my xampp
installation. It may varies depending on your OS
and If not specified, the MAGIC environment variable is used, for more information, visit fileinfo . Also, this may help you. It's not related to Laravel
but your php
installation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.