2010-07-08 68 views
1

如何上傳文件?計算器我不能頁面代碼,以便請檢查此鏈接:http://pastebin.org/386639Zend Framework - 如何上傳文件

在此先感謝

更高版本: 後來我更新了這個如下,因爲ZF並不友好,他們仍然保持一切絕密! :P

public static function mvUploadFile() 
    { 

    // 
    // $_GET/_POST/FILE what ever 
    // 
    $fname = basename($_FILES['attachment']['name']); 
    $_fname = strtolower (end(explode('.',$fname))); 
    Zend_Debug::dump( $_FILES ); 


    // 
    // Filter the file 
    // 
    switch($_fname) 
    { 
     case ($_fname == 'jpg' || 
      $_fname == 'jpeg' || 
      $_fname == 'gif' || 
      $_fname == 'bmp' || 
      $_fname == 'png' || 
      $_fname == 'html' || 
      $_fname == 'pdf' || 
      $_fname == 'doc' || 
      $_fname == 'docx' || 
      $_fname == 'xls' 
     ): 
     $target_path = APPLICATION_PATH . "/../public/files/textual_translation_attachment/"; 
     //chmod("../up" , 0777); 

     $target_path = $target_path . basename($_FILES['attachment']['name']); 

     if(move_uploaded_file($_FILES['attachment']['tmp_name'], $target_path)) { 
      //echo "The file ". basename($_FILES['file']['name']). " has been uploaded"; 
      //$_sql = "insert into a (huis,image) values ('$_app','$_file')"; 
      // send the file name only ..... 
      //echo $fname ; 
     }else{ 
      //echo "error "; 
     } 
     break; 
    } 


    return $fname; 

    } 
+0

您不必使用move_uploaded_file()以如在下面評論建議來完成。使用Zend_Form_Element的本地方法receive()。例如:$ form-> file-> receive(); – 2010-07-09 07:28:09

回答

1

如果

Zend_Debug::dump($_FILES); 

你看到你的文件嗎?

+1

我看到這個: array(1){ [「icon」] => array(5){ [「name」] => string(8)「test.csv」 [「type」] => string (8)「text/csv」 [「tmp_name」] => string(14)「/ tmp/phpcdvLDl」 [「error」] => int(0) [「size」] => int(793) } } – YumYumYum 2010-07-08 20:02:12

+0

然後文件就在那裏。谷歌瞭解如何從那裏移動文件的一些教程。 google move_uploaded_file() – Iznogood 2010-07-08 20:12:23

+1

$ form-> file-> receive();足夠。您不需要使用move_uploaded_file()。 – 2010-07-09 11:25:18