Zend Framework - 如何上传文件

时间:2010-07-08 19:19:39

标签: zend-framework zend-form

如何上传文件? Stackoverflow我无法访问网页代码,因此请查看以下链接:http://pastebin.org/386639

提前致谢

后来: 后来我更新了这个,因为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;

  }

2 个答案:

答案 0 :(得分:1)

如果你

Zend_Debug::dump($_FILES);

你看到你的档案吗?

答案 1 :(得分:0)

如果您使用的是jQuery,则可能需要尝试上传。这可以使用 Zend Framework Uploadify扩展

http://gondo.webdesigners.sk/zend-framework-uploadify-extension/