symfony2 fileupload(致命错误:允许的内存大小耗尽)

时间:2012-04-05 08:57:06

标签: php symfony doctrine

我面临一个非常奇怪的问题。

我尝试用Symfony2和Doctrine实现一个简单的附件上传器。

所以我跟着这本食谱文章http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html

一切似乎都很好,但是当我尝试上传140KB的文件时,PHP会抛出一个致命的错误。

这是我的验证:

/**
 * @Assert\File(
 *      maxSize="4M",
 *      maxSizeMessage="Allowed maximum size is {{ limit }}"
 * )
 */
public $file;

这是我的php.ini

memory_limit = 256M
max_input_time = 60
max_execution_time = 30
file_uploads = On
upload_max_filesize = 128M

所以一切都应该没问题,脚本需要500毫秒才能得到错误: 致命错误:允许的内存大小为268435456字节(尝试分配122字节)

当我增加memory_limit它没有改变任何东西时,内存大小增加但它仍然试图分配122个字节。 其他一切工作都很好,只是文件上传中断。

有没有猜到发生了什么?

修改 是的我做了{{ form_enctype(form) }},所以我会发布uploadAction。它非常复杂,因为模型充满了外键,我会剪掉那些无关紧要的部分:

public function createAction(Request $request)
    {
        $em = $this->getDoctrine()->getEntityManager();

        $conference = new Conference();
        $conference->setArchived(false);
        $conference->setLastModification(new \DateTime());

        $form = $this->createForm(new ConferenceType(), $conference);

        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);

            if ($form->isValid()) {
                $registrationForm = $conference->getRegistrationForm();

                $em->persist($conference->getLocation());

                $conference->getImage()->upload();
                $em->persist($conference->getImage());

                // lots of other stuff is going on (does not refer to the upload processs

                $em->flush();

                return $this->redirect($this->generateUrl('KnowHowERegistrationBackendBundle_registrationform_create'));
            }
        }

        return $this->render('KnowHowERegistrationBackendBundle:Conference:create.html.twig',
            array(
                'form' => $form->createView(),
                'conference' => $conference
            ));
    }

我希望有人能够重现它或找到解决方案。

1 个答案:

答案 0 :(得分:0)

没有什么能真正跳出来。这绝对是一种解决问题的答案。

首先评论这些行:

            $conference->getImage()->upload();
            $em->persist($conference->getImage());

验证其他一切正常。并发布完整的错误消息。可能是那里的线索。

相关问题