Hello,
I have a script that works great, basically i have a mysql database that contains information about files; like filename, description, size etc.
The information is displayed on a webpage in a nice formatted table. each file has a link next to it and once pressed the script below will get the file from server and hand it over to the visitor. It works great like it should.
My problem is i am sharing the script with loads of people, some want to force download images, audio files, video files, compression files and so on.
The script at the moment has 1 header and that is to force download a zip file. What i don't understand is how can i make my script below force download any file?
I did add about 15 headers for all popular video, audio, image files but it tends to use the last header in the script plus if for example i use just the 1 header
header('Content-Type: application/zip');
yet one of the files is a .exe file it appears in the download window when i click download as: an exe file but with a zip icon because it is using the zip header not the
header('Content-type: application/octet-stream');
header, basically once downloaded it shows as imagename.exe.zip
Here is my script, can someone please explain how i can get my script to force download any file? like i said the script is being shared so i need to ensure that any file will be forced to be downloaded.
It's basically going to be a relatively simple download manager script, i am just wondering how other such scripts manage to work around the issue i am not sure how to solve. If they were just .zip files then the script would work a treat but obviously i would want it to support more than one file type to force download.
Thanks
PHPLOVER
<?php
if( isset( $_GET['file'] ) ) {
# get filename
$getfile = $_GET['file'];
# path to file
$filepath = ''.$_SERVER['DOCUMENT_ROOT'].'/files/'.$getfile.'';
# check file exisits, if it does force download/header
if ( file_exists( $filepath ) ) {
# Headers
header('Content-type: application/zip');
header('Content-disposition: attachment; filename='.$getfile.'');
header("Content-length: " . filesize( $filepath ));
readfile($filepath);
} else { # else if file does not exist tell them and exit.
echo "<h1> File Does Not exist </h1>";
echo "The file you have requested does not exist. <br />";
echo "Please click <a href=\"index.php\">here</a> to go back.";
exit;
}
} else { # else no parameter specified redirect back to downloads table
header('LOCATION: index.php');
exit;
}
?>