Jump to content

Download multiple files using one button


andytan91

Recommended Posts

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

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

}

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");
	}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.