2012-04-05 100 views
2

我正面臨一個非常奇怪的問題。symfony2 fileupload(致命錯誤:允許的內存大小用盡)

我試着用Symfony2和Doctrine實現一個簡單的附件上傳器。

所以我followes這個食譜文章http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html

,一切似乎不錯,但PHP拋出一個致命的錯誤,當我嘗試上傳文件140KB。

這是我的驗證:

/** 
* @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 

所以一切都應該罰款,腳本需要的東西,500ms左右才能到錯誤: 致命錯誤:允許內存大小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 
      )); 
    } 

我希望有人能夠複製它或者找到一個解決方案。

+0

只是在黑暗中的一個狂野的鏡頭,但你有你的模板form_enctype(表單)?如果你這樣做,那麼也許發佈你的uploadAction代碼。可能還有一個遞歸正在進行。 – Cerad 2012-04-05 13:45:13

回答

0

沒有真正跳出來。這絕對是一種解決問題的答案。

開始通過註釋掉這些行:

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

驗證一切工作正常。併發布完整的錯誤消息。可能是在那裏的線索。

相關問題