2012-07-23 20 views
0

以下Zend框架的形式无法正常工作:Zend_Form_Element_File不工作

<?php 

class Application_Form_Auth extends Zend_Form 
{ 

    public function init() 
    { 
     $this->setAttrib('enctype', 'multipart/form-data'); 
     $this->setMethod('post'); 

     $username = $this->createElement('text','username'); 
     $username->setLabel('Username:') 
       ->setAttrib('size',10); 

     $password = $this->createElement('password','password'); 
     $password->setLabel('Password') 
       ->setAttrib('size',10); 

     $file = new Zend_Form_Element_File('file'); 
     $file->setLabel('File') 
      ->setDestination('/data/uploads') 
      ->setRequired(true); 

     $reg = $this->createElement('submit','submit'); 
     $reg->setLabel('save');    

     $this->addElements(array(
      $username, 
      $password, 
      $file, 
      $reg 
     )); 

     return $this; 
    } 
} 
?> 

的问题在于:

->setDestination('/data/uploads') 

当我删除从表单正常工作的这行代码。我有/data/uploads的上传文件夹,并且目录的权限设置为777。我该如何解决这个问题?谢谢

+2

'data'文件夹是否确实位于服务器的根目录下,还是位于您的应用程序目录中?我想你可能会指定错误的路径。试试'APPLICATION_PATH。 '/ data/uploads''来代替。 – drew010 2012-07-23 04:50:43

回答

1

你使用任何域名(与本地主机)。如果是的话,你应该使用数据/上传。数据目录应该位于公共目录中。如果您有任何域,您应该使用baseUrl使用目标路径。