I want to create a file called "download.php" to handle the downloading of brochures. What I am trying to achieve is as follows:

1) From the brochure page send the brochure id to the download.php (No problem with this)
2) Select the correct brochure from the database by the id sent from brochure page
3) Insert the directy name + file name into the header file area. (this is messed up somehow)

I'm new to php and not sure how to write the variables into the header. The way I have it at the moment it's not placing in the dir or the file name, when I click on download instead it opens the download window, but just the id is in there instead of the file name. Thruth is I'm not sure how to get it to work, I've been trying all morning. If anyone out there could tell me what I've done wrong I'd be greatful.

As I'm going no where fast! Have tried searching net for solution, but haven't come up with anything.

Big. big thank you in advance,
Linda

<?php
	$id=$_GET['id'];

include '../inc/hearse.inc';

@mysql_connect($host,$user,$password) or die ("Unable to connect to server!");
@mysql_select_db($database) or die( "Unable to connect to database, please try later!");

$query=" SELECT * FROM brochure WHERE id='$id'";
$result=mysql_query($query);
mysql_close();

$filename=mysql_result($result,"filename");
$dir=mysql_result($result,"dir");


header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="'.basename($dir,$filename).'"');

?>  

    You know, if you create a link like this <a href='file.pdf'>Filename</a> the browsers will figure out to either open it with a pdf plug-in or ask the user what to do with the file. You only need to mess with the headers when you have a buffer full of a raw pdf string.

      tjohnson_nb wrote:

      You know, if you create a link like this <a href='file.pdf'>Filename</a> the browsers will figure out to either open it with a pdf plug-in or ask the user what to do with the file. You only need to mess with the headers when you have a buffer full of a raw pdf string.

      Hi tjohnson

      I have a direct link to the file called (view file in browser), but I would also like to add (if possible) a direct download link. Without the user having to right click etc! Most people forget to right click (even when they are reminded on the page), then have to sit and wait for the reader to kick in. I need the website to be as stress free as possible. You see it's my partners business site, and he's a Funeral Director. So you will appreciate that most if not all of the users, are probably stressed out to the max when they are using the site!

      Best wishes,
      Linda

        I wasn't referring to 'right-clicking', I meant 'left-clicking'. Not sure what you expect this download script to do?

        EDIT: Sorry I misunderstood. So you want a script that will start a download automatically - sorry never done that!

        Found this;

        <?php
        // We'll be outputting a PDF
        header('Content-type: application/pdf');
        
        // It will be called downloaded.pdf
        header('Content-Disposition: attachment; filename="downloaded.pdf"');
        
        // The PDF source is in original.pdf
        readfile('original.pdf');
        ?>
          Write a Reply...