2012-07-23 19 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使用目標路徑。