2010-07-08 78 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