This is the calling form:
[code=php]
function display_docs($class_num) {
echo “<div id=’doc_files’>n<ul>n”;
$folder = “word_documents/$class_num/”;
$_SESSION[‘location’] = $folder;
$handle = opendir($folder); #opens the directory so we can read the files out
while($file = readdir($handle)){ #loop through the files
$ext = substr($file, -4);
if($ext == “.doc”){
echo “<li><a href=’download.php?id=$file’>$file</a></li>n”;
}
}
and this is the download.php, which seems to work in FF but when I try to open the file in IE it changes the file name so it won’t open, it will download and open fine, but it doesnt open in the browser.
[code=php]
session_start();
if (!isset($_GET[‘id’]) || !file_exists($_SESSION[‘location’].$_GET[‘id’])) {
die(‘The document does not exist.’);
}
$file_location = $_SESSION[‘location’].$_GET[‘id’];
header(‘Content-type: file/.doc’);
header(‘Content-Disposition: attachment; filename=”‘.basename($_GET[‘id’]).'”‘);
echo implode(null, file($file_location));
Ok, so what i’m asking is this: is this the correct coding to perform this action?
In addition, if I have 40 or 400 docs and I would like to offer them all to download, do I have to manually place them in a zip file to be included as a download link or can php zip all the files in the directory and send them?
thanks.