473,414 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Creating download link for a pdf

Using:
Mysql 5.0.15
php 5.1.6
apache 2.2.3

I am trying to create a download link for various pdfs which I have stored in a
mysql DB.

I am having trouble with the header fields when clicking the link.

Here is the code that sends the pdf called using
<a href="download.php?id=4">Blah</a>

Output is delayed from php.ini (output_buffering = 4096)

What http headers should I be sending.

This works most of the time like this, but in IE6 I get few strange results
sometimes.

1. Clicking on a new page after downloading the pdf - the page is blank unless I
refresh
2. The URL in the address bar does not update even though the page does.
3. If I leave out the Content_Disposition header and set the Content-Type:
application/pdf. The browser just displays the PDF as text.

<?php
include($_SERVER["DOCUMENT_ROOT"] . "/../php/common.inc");
include($_SERVER["DOCUMENT_ROOT"] . "/../php/prepend.php");

$db=new Interlex_DB;

if(isset($_GET["id"]))
{
$query=sprintf("SELECT pdf, filename, length(pdf) AS len FROM broadsheets
WHERE broadsheet_id='%d' AND active=1", $_GET["id"]);
$db->query($query);
if($db->next_record())
{
if(!headers_sent())
{
header("Accept-Ranges: bytes");
header("Content-Transfer-Encoding: Binary");
header("Content-Type: application/force-download");
header(sprintf("Content-Length: %d", $db->f("len")));
header(sprintf("Content-Disposition: inline; filename=\"%s\"",
$db->f(filename)));
echo $db->f("pdf");
//exit;
}
}
}
?>

--

Adrian

Think you know a language? Post to comp.lang... and find out!
Nov 1 '06 #1
1 2064
I would set output buffering to just on because 4096 just buffers the
first 4096 bytes; not always what you want. Also, if you're displaying
a PDF, many browsers have built in plugins to handle pdfs. If the users
wants to download it, then they can just use the save function in their
browsers to download the pdf.
Adrian wrote:
Using:
Mysql 5.0.15
php 5.1.6
apache 2.2.3

I am trying to create a download link for various pdfs which I have stored in a
mysql DB.

I am having trouble with the header fields when clicking the link.

Here is the code that sends the pdf called using
<a href="download.php?id=4">Blah</a>

Output is delayed from php.ini (output_buffering = 4096)

What http headers should I be sending.

This works most of the time like this, but in IE6 I get few strange results
sometimes.

1. Clicking on a new page after downloading the pdf - the page is blank unless I
refresh
2. The URL in the address bar does not update even though the page does.
3. If I leave out the Content_Disposition header and set the Content-Type:
application/pdf. The browser just displays the PDF as text.

<?php
include($_SERVER["DOCUMENT_ROOT"] . "/../php/common.inc");
include($_SERVER["DOCUMENT_ROOT"] . "/../php/prepend.php");

$db=new Interlex_DB;

if(isset($_GET["id"]))
{
$query=sprintf("SELECT pdf, filename, length(pdf) AS len FROM broadsheets
WHERE broadsheet_id='%d' AND active=1", $_GET["id"]);
$db->query($query);
if($db->next_record())
{
if(!headers_sent())
{
header("Accept-Ranges: bytes");
header("Content-Transfer-Encoding: Binary");
header("Content-Type: application/force-download");
header(sprintf("Content-Length: %d", $db->f("len")));
header(sprintf("Content-Disposition: inline; filename=\"%s\"",
$db->f(filename)));
echo $db->f("pdf");
//exit;
}
}
}
?>

--

Adrian

Think you know a language? Post to comp.lang... and find out!
Nov 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Asaf | last post by:
Hi, Is there a way to create a temporary download link and to know when the client has finished downloading the file? Thanks in advanced,
1
by: J.S. | last post by:
I have the URL for the Assenbly Linker page: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfAssemblyGenerationUtilityAlexe.asp but I can't find a download link...
0
by: kain razial | last post by:
ANYOTHER NEEDS ALSO CONTACT ME.I WILL HELP YOU TO GET THAT TEKLA XSTEEL V 12 DOWNLOAD LINK. http://www.sendspace.com/file/zem32r
0
by: kain razial | last post by:
ANYOTHER NEEDS ALSO CONTACT ME.I WILL HELP YOU TO GET THAT TEKLA XSTEEL V 12 DOWNLOAD LINK. http://www.sendspace.com/file/zem32r
2
by: snowycat | last post by:
Hi I am writing a PHP script and using MySQL to store visitor details, and I am supplying a link for a visitor to download some zip files. Can someone help with a script that detects that the...
0
by: STAGED | last post by:
Hi I searched "f77" and "g77" and came up empty. I need a direct download link for a Linux (using Ubuntu) compliant 1.) Fortran 77 2.) Useful and common libraries If possible an IDE f77...
12
by: Bob Bedford | last post by:
I've to build a website where the customer can buy an image. I'm thinking in the 2 ways to let people get those images: receive them by Email or send them an image link wich validity is limited in...
1
by: syminder | last post by:
Anybody have the download link for JDK 5? I need it support JDBC in Oracle XE 10g, this Oracle XE JDBC version is not support the lastest JDK 6. It is very lousy but i need at least this weekend...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.