2011-04-28 52 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