0

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);



	}
?>
3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by itisnot_me
0

thanks. that sheds a little more light on the matter.

the file name is correct as it was stored in the DB but the file is in another directory. i have tried to put the force download script in the directory just to get som internal error.

0

if the file is stored in a blob in the database, print the database field
if the filename only is stored in the database, without the directory structure

readfile('./pathtofolder/'.$file); //or
readfile("./pathtofolder/$file");

always forget which one is the right form

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.