How to open a file dialogue box from Zend AMF + AS3
I want to send a request to my Zend AMF to Open a Dialogue Box for a File Download.
The process:
Send a request to the Zend Server from my flash App, process the MYSQL results with PHP, then send the result to the browser as a file download (.csv) AND a result true or false to the app
I have the code working just fine outside of the Zend Environment, but of course, when i go to echo/print the file - it sends back to flash with nothing happening.
Is there any way around this?
$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;
Or, do i have to just request this outside of the zend request...?
So far i have changed the headers to make use of the zend headers:
$this->setHeader('Content-Type', 'application/octet-stream');
$this->setHeader('Content-disposition:', 'attachment');
$this->setHeader('filename:', 'file.csv');
But am unsure how to the attach $file to 'file.csv' and then return a result of true to Flash AND download the file.. (zend noob here i am afraid..)
Are you using Zend MVC? If so make sure you are not rendering a layout....
I am not too happy with the exit; statement... since zend uses an mvc framework, it builds the response and renders it. Causing the script to exit might mean the content does not get rendered properly.
Also, make sure you use the correct zend functions to build the headers, it is very possible that zend is adding conflicting headers to the response. See http://framework.zend.com/manual/en/zend.controller.response.html
The process could be :
-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
Since it's a zip file url, the browser should open a dialog box.
According to this excerpt from the docs, it seems that your options are fairly limited, as it's not only a Flash issue...
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.)
精彩评论