Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Make a web page download PDF, DOC, POWER POINT and images
    primarykey
    data
    text
    <p>I have been trying to make a download page that would download different file formats (PDF, DOC, POWER POINT and images). This works with pdf, but the first problem is that sometimes it makes my whole system reboot or it redirects to other pages whose contents are not human readable. Secondly, the other file formats (MIME) that are not application/pdf would not just download, sometimes the pdf downloads but when I try to open it an error message would be displayed, saying its a bad file format. Below are the headers I use to make the download page.</p> <pre><code>header('Content-Type: application/{$_GET['mime']}'); header("Content-Disposition:attachment; filename='{$_GET['name']}'\n"); header("Content-Length:{$_GET['size']}\n"); header('Content-Transfer-Encoding: binary'); </code></pre> <p>The following are the various MIME I tried to allow:</p> <pre><code>$permitted = array('text/html', 'image/jpeg', 'image/png', 'image/jpg','image/gif', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/pdf', 'text/plain', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.openxmlformatsofficedocument.presentationml.presentation'); </code></pre> <p>Here's the code (almost) all together:</p> <pre><code>$flag = false; $filepath = $_GET['path'] . $_GET['name'] foreach($permitted as $value) { if($_GET['mime'] == $value) { $flag=true; break; } if($flag == true) { header('Content-Type: application/{$_GET['mime']}'); header("Content-Disposition:attachment; filename='{$_GET['name']}'\n"); header("Content-Length:{$_GET['size']}\n"); header('Content-Transfer-Encoding: binary'); readfile($filepath) } </code></pre> <p>I would appreciate all responses as I am using this for my project in school, Thanks....</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload