2010-12-03 42 views
1

我想向我的Zend AMF發送請求以打開文件下載的對話框。如何從Zend AMF + AS3打開文件對話框

的過程:

發送到從我的Flash應用程序,處理結果MYSQL用PHP Zend服務器的請求,然後將結果發送到瀏覽器的文件下載(.CSV)和一個結果真或虛假的應用程序

我有代碼工作在Zend環境以外,但當然,當我去echo /打印文件 - 它發回閃光沒有任何事情發生。

有沒有辦法解決這個問題?

 $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'); 

但我不確定如何在$文件附加到「FILE.CSV」,然後返回真到Flash結果並下載文件..(zend noob在這裏我很害怕..)

回答

0

您是否使用Zend MVC?如果是這樣,確保你沒有渲染布局....

我不太滿意退出;聲明...自從zend使用mvc框架以來,它會構建響應並呈現它。導致腳本退出可能意味着內容無法正確呈現。

另外,請確保您使用正確的zend函數來構建標頭,zend很可能會向響應添加衝突的標頭。見http://framework.zend.com/manual/en/zend.controller.response.html

+0

我將不得不採取一個仔細看了看那個。如果我誠實 - 這對我的技能有點深遠,但感謝把我放在正確的方向! – Beans 2010-12-05 22:29:30

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文件的URL,瀏覽器應該打開一個對話框。

據來自文檔的摘錄,似乎你的選擇是相當有限的,因爲它不僅是一個閃光的問題...

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.) 
+0

不幸的是,當不直接綁定到鼠標事件時,flash不允許產生新窗口。處理as3 + zendAMF時令人沮喪的問題。你的方法可以工作,但只有當文件url返回後,用戶才能點擊另一個按鈕。不是一個理想的場景 - 但確實有效。 – Beans 2010-12-05 15:34:33