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

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.