如何从Zend AMF + AS3打开文件对话框

时间:2010-12-03 17:30:19

标签: php actionscript-3 zend-framework header

我想向Zend AMF发送请求,打开文件下载对话框。

过程:

从我的Flash应用程序向Zend服务器发送请求,使用PHP处理MYSQL结果,然后将结果作为文件下载(.csv)发送到浏览器,结果为true或false给应用程序

我的代码在Zend环境之外工作得很好,但当然,当我去回显/打印文件时 - 它会发回闪存而没有任何事情发生。

这有什么办法吗?

        $file = "";

        $outtype = "Content-type: application/octet-stream";
        header($outtype);

        $outtype = 'Content-disposition: attachment; filename="file.csv"';           
        header($outtype);

        $stmt->bind_result($id, $username, $email, $location);

        while($stmt -> fetch()){

            $file .= '"'.addslashes($col1).'"';
            $file .= ',"'.addslashes($col2).'"';
            $file .= ',"'.addslashes($col3).'"';
            $file .= "\n";

        }   

        print $file;
        exit;

或者,我是否必须在zend请求之外请求...?

到目前为止,我已经更改了标头以使用zend标头:

        $this->setHeader('Content-Type', 'application/octet-stream');           
        $this->setHeader('Content-disposition:', 'attachment');
        $this->setHeader('filename:', 'file.csv');

但我不确定如何将attach $文件附加到'file.csv'然后将结果返回到Flash并下载文件..(Zend noob here恐怕..)

2 个答案:

答案 0 :(得分:0)

您使用的是Zend MVC吗?如果是这样,请确保您没有渲染布局......

我对出口不太满意;声明...因为zend使用mvc框架,它会构建响应并呈现它。导致脚本退出可能意味着内容无法正确呈现。

另外,请确保使用正确的zend函数来构建标头,zend很可能会在响应中添加冲突的标头。见http://framework.zend.com/manual/en/zend.controller.response.html

答案 1 :(得分:0)

这个过程可能是:

-1 Send a request to Zend Framework
-2 Query Mysql, process the result & write the file to the server
-3 Zip the file
-4 return the file url to Flash
-5 inform the user that the file is ready for download
-6 a user click calls navigateToURL from Flash, using the returned url

由于它是一个zip文件网址,浏览器应该打开一个对话框。

根据文档的摘录,您的选择似乎相当有限,因为它不仅仅是Flash问题......

In Flash Player 10 and later running in a browser, using this method 
programmatically to open a pop-up window may not be successful. 
Various browsers (and browser configurations) may block pop-up windows 
at any time; it is not possible to guarantee any pop-up window will appear. 
However, for the best chance of success, use this method to open a 
pop-up window only in code that executes as a direct result 
of a user action (for example, in an event handler for a 
mouse click or key-press event.)