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



	}
?>

I don't have an answer for you but you may want to look at:
http://ca.php.net/manual/en/function.header.php

The source of the file is dependent on the $file variable. You need to check that it is correct. The header statement defines the name for the output file.

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.

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

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.