ok i have been trying to really find out how to do this but with no help.
i got this script to work but the problem is that it is not getting the file from the directory that it is stored in. it is just trying to find it in the root directory where this file is stored.
would any one know how to get it to download the file from the directory it is stored in.
and i have tried putting the directory
header('Content-Disposition: attachment; filename="documents/'.$name.'.'.$ext.'"');
but that did not work. it just adds documents to the file name
<?php
session_start(); // NEVER forget this!
if ($_SESSION['agent'] == 'yes'){
session_destroy();
}
if(!isset($_SESSION['login_email']) && !isset($_SESSION['company_id']) && !isset($_SESSION['admin']) && !isset($_SESSION['name']))
{
header("location:login.php");
}
$login_email = $_SESSION['login_email'];
$company_id = $_SESSION['company_id'];
$admin = $_SESSION['admin'];
$name = $_SESSION['name'];
require_once("functions.php");
connect_to_db();
$file = $_GET['file'];
$result = mysql_query("SELECT * FROM paperwork WHERE company_id='$company_id' and file='$file'");
while($myrow = mysql_fetch_array($result))
{
$name = $myrow['name'];
$ext = substr(strrchr($file, "."), 1);
switch($ext) {
case 'pdf':
$ctype="application/pdf";
break;
case 'doc':
$ctype="application/msword";
break;
case 'xls':
$ctype="application/vnd.ms-excel";
break;
case 'ppt':
$ctype="application/vnd.ms-powerpoint";
break;
}
// We'll be outputting a PDF
header('Content-type: '.$ctype.'');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="'.$name.'.'.$ext.'"');
readfile($file);
}
?>