小编Amu*_* B.的帖子

无法在symfony2.7中上传视频

我正在尝试制作一个带有文件字段的表单来上传视频和音频文件.我可以上传音频文件,但不能上传视频.当我上传MP3文件时,扩展名是.mpga而不是.mp3.

这是我的代码,(我自动化所有类型的文件,以避免与mimetypes有关的问题):

        $product = new Bfile();
        $form_upload = $this->createForm(new BfileType(), $product);
        $form_upload->handleRequest($request);

        if ($form_upload->isValid()) {
            // $file stores the uploaded PDF file
            /** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */

            $file = $product->getBrochure();

            // Generate a unique name for the file before saving it
            $fileName = md5(uniqid()).'.'.$file->guessExtension();

            // Move the file to the directory where brochures are stored
            $brochuresDir = $this->container->getParameter('kernel.root_dir').'/../web/uploads';
            $file->move($brochuresDir, $fileName);

            // instead of its contents
            $product->setBrochure($fileName);

            // ... persist the $product variable or any other work

            return $this->render(...);
        }
Run Code Online (Sandbox Code Playgroud)

我的表格: …

php video upload symfony

2
推荐指数
1
解决办法
1420
查看次数

标签 统计

php ×1

symfony ×1

upload ×1

video ×1