andytan91 Posted August 31, 2010 Share Posted August 31, 2010 Hi guys i am kinda stuck at a part where i want a download button to prompt out two download windows in a click. Currently i am able to prompt out one download window only. I have tried putting another header line of Content Disposition but it doesn't work..i will appreciate if you guys can help me out, thanks! The desired scenario will be WinSCP.exe download prompt will appear first, follow by auditgroup.bat $file1 = "WinSCP.exe"; $file = "auditgroup.bat"; //Set headers header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: ASCII"); //Read the file from disk readfile($file); Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2010 Share Posted August 31, 2010 The HTTP response to a HTTP request can only consist of one file. You must generate a separate HTTP request/response for each file. Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 If it's really important you send both at the same time you should have the files zipped together, either in advance or dynamically using PHP's ZIP extension functions. Quote Link to comment Share on other sites More sharing options...
andytan91 Posted August 31, 2010 Author Share Posted August 31, 2010 thanks for the replies guys, i think zipping it wouldn't be ideal because my current situation requires user to download winscp.exe to c drive and then run auditgroup.bat straightaway after winscp is downloaded... may i ask how do to generate a separate HTTP request/response? I tried the codes below but it only prompts out the download window for auditgroup.bat if(isset($_POST['submit']) == "Run") { $file = "auditgroup.bat"; $file1= "WinSCP.exe"; //Set headers header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file1"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: ASCII"); //Read the file from disk readfile($file1); header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); //Read the file from disk readfile($file); } Quote Link to comment Share on other sites More sharing options...
jayarsee Posted August 31, 2010 Share Posted August 31, 2010 You can have the link call a JavaScript function that tries to open two separate new windows which both call on a PHP script that differentiates between the files by being passed GET or POST variables from the JavaScript, and accordingly sends the proper file, or less efficiently, by calling two totally separate URLs/PHP scripts from the JavaScript (or the files themselves). Using PHP to stream files, there's something to be aware of here, which is that the headers that different browsers, namely stupid IE, require to force a download varies. I have found this to be invaluable for dealing with such issues: if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")==false) { header("Content-type: {$this->contentType}"); header("Content-Disposition: inline; filename=\"{$this->filename}\""); } else { header("Content-type: application/force-download"); header("Content-Disposition: attachment; filename=\"{$this->filename}\""); }; if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")==false) { header("Cache-Control: no-cache"); header("Pragma: no-cache"); } Quote Link to comment Share on other sites More sharing options...
andytan91 Posted September 1, 2010 Author Share Posted September 1, 2010 thanks guys, i have solved this using JavaScript! I appreciate your help very much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.