Force loading the msi file

I must have a busy day. I cannot figure it out.

I have a page on my website that needs to force the download of the msi file, but I want to leave the html page specified with download instructions.

So far, I have tried the following tag in html (note that I have access to the body of this page)

<meta http-equiv="Refresh" content="0; URL=file.msi">

      

however in firefox this showed the binary as garbled text.

Next, I tried to insert the following php

$file = "file.msi";
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 5');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;

      

However, this closed the tab / window and left no installation instructions.

Finally, I tried the following in html:

<META HTTP-EQUIV="Content-Type" CONTENT="application/octet-stream"> 
<meta http-equiv="content-disposition" content="attachment; filename=file.msi" />

      

But this does not allow uploading the file. Any pointers are greatly appreciated.

+3


source to share


3 answers


Tags

<meta>

apply to the page in which they are embedded. They will not change how the file is loaded, which is considered a completely separate page.



You should have something like this <a href="downloadmsi.php" target="_new" />download</a>

to load in a different window than the instructions page.

0


source


Assuming Apache, if you want to use a file .htaccess

, you can add the following:

AddType application/octet-stream .msi

      



According to this source . Then you can just link to the file.

0


source


I found this link which helped me create a PHP file to link to to point the .msi to download. Worked for the first time.

Visible download page, downloads.php, possibly

<a href="/downloads/?version=App.Installer.msi">download now</a>

      

Sever processing page from href above i.e. example.com/downloads/index.php

$root = realpath($_SERVER["DOCUMENT_ROOT"]);
$file_dl = $_GET['version'];
header('Content-disposition: attachment; filename='.$file_dl);
header('Content-type: application/x-ole-storage');
readfile($root.'/downloads/'.$file_dl);

      

Also, not sure if it was necessary, but I added to the .htaccess file: AddType application/octet-stream .msi

as suggested by Marc B

0


source







All Articles