2011-04-28 47 views
0

必須是一些簡單的解決辦法,但作爲初學者,我已經花了2天的時間來了解。我有一個簡單的表單(「enctype =」multipart/form-data「),輸入的文本和文件很少,我不能得到什麼錯誤,我可以通過getParameter()獲取用戶的文本數據,但無法獲取文件。的GetFiles()我是在Ubuntu 11.04 PHP5.3Symfony 1.4無法獲得提交的文件

代碼:

窗體類:

public function configure() 
    { 
    $this->setWidgets(array(
     'vendor' => new sfWidgetFormInputText(array(), array('class' => 'form-text')), 
     'image'  => new sfWidgetFormInputFile(array(), array('class' => 'form-text')), 
     'city'  => new sfWidgetFormInputText(), 
     'email' => new sfWidgetFormInputText(array('default' => '[email protected]')), 
     'contacts' => new sfWidgetFormTextarea(), 
     'description' => new sfWidgetFormTextarea(), 
    )); 
    $this->setValidators(array(
     'vendor' => new sfValidatorString(array('required' => false)), 
     'image' => new sfValidatorFile(array(
      'required' => false, 
     'path'  => sfConfig::get('sf_upload_dir') . '/images', 
     'mime_types' => 'web_images')), 
     'city' => new sfValidatorString(array('required' => false)), 
     'email' => new sfValidatorString(array('required' => false)), 
     'contacts' => new sfValidatorString(array('required' => false)), 
     'description' => new sfValidatorString(array('required' => false)), 
    )); 
    $this->widgetSchema->setNameFormat('pv[%s]'); 
    } 

行動:

public function executeCreate(sfWebRequest $request) 
{ 
$this->forward404Unless($request->isMethod(sfRequest::POST)); 
return $this->renderText(var_dump($request->getParameter('pv'))); //this array include vars from form 
//return $this->renderText(var_dump($request->getFiles('pv'))); //empty array 
} 
+0

好吧,我明白我的問題,我是用JQ插件,並提交按鈕是jq_submit_to_remote()這是不是演戲正如我所想的那樣。 – bduisenov 2011-04-29 04:58:07

回答

0

您的表單構件配置是否與以下內容類似?

$this->setWidget('attachment', new sfWidgetFormInputFileEditable(array(
    'file_src' => '/upload/' . $this->getObject()->getAttachment(), 
    'edit_mode' => true, 
    'with_delete' => true, 
))); 

$this->setValidator('attachment', new sfValidatorFile(array(
    'path' => sfConfig::get('sf_upload_dir'), 
    'required' => false 
))); 
$this->setValidator('attachment_delete', new sfValidatorPass()); 

此外,檢查,如果你有你的上傳文件夾的權限:

chmod 777 web/upload/ 
0

你綁定的文件以及表單參數,像這樣?

$this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); 
+0

如果我沒有使用窗體對象保存,我必須綁定變量嗎? – bduisenov 2011-04-29 04:37:14

+0

不,你可以傳入null:'$ this-> form-> bind(null,$ request-> getFiles($ this-> form-> getName()));' – matt 2011-05-03 15:41:25

-2

您必須添加ENCTYPE =「多/ ...」屬性窗體

+1

嘗試閱讀之前的問題你回答;-)他說他有他的形式多部分屬性。 – Tankhenk 2013-05-22 09:37:09