【发布时间】:2021-02-08 16:04:56
【问题描述】:
我无法在 Symfony 5.1 中上传 .jpg 文件,我尝试了很多东西, 如果我在 symfony 文档 (https://www.iana.org/assignments/media-types/media-types.xhtml) 中搜索 mimtype 指南,不支持 simple.jpg,那么我该怎么做 它适用于其他文件格式。最后一次尝试: (我只想上传图片和pdf)
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\Image;
class CapebType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', FileType::class, [
'label'=> 'Chargez ma carte carte Capeb',
'required' => true,
'constraints' => [
new File([
'maxSize' => '5M',
'mimeTypes' => [
'image/jpeg,', 'image/pjpeg', 'image/png', 'image/gif', 'image/jpg',
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Le fichier n\'est pas valide, assurez vous d\'avoir un fichier au format PDF, PNG, JPG, JPEG)',
]),
]
])
->add('submit', SubmitType::class, [
'label'=> 'Envoyez ma carte CAPEB',
])
;
}
【问题讨论】:
标签: symfony-forms file-type symfony5 imagecreatefromjpg