473,372 Members | 1,615 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,372 software developers and data experts.

Looking for a script to download pdf file from server

Hi,

I am looking for a script that will download a pdf file from my server without
opening it in IE. I want peeople to be able to simply download the file and
store it in a location on their PC. Any help greatly appreciated.

Regards
Dynamo

May 23 '06 #1
11 8317
Rik
Dynamo wrote:
Hi,

I am looking for a script that will download a pdf file from my
server without opening it in IE. I want peeople to be able to simply
download the file and store it in a location on their PC. Any help
greatly appreciated.


header('Content-disposition: attachment');

Grtz,
--
Rik Wasmus
May 23 '06 #2
Many thanks but somehow I dont think that snippet of code on its own will do
what I want. I was looking for the complete code. I have tried the following but
it failed miserably. What am I doing wrong?

<?php
$dir_name = "/books/";
$file = "downloadtest.pdf";

$content = file_get_contents($dir_name . $file);

header('Content-Type: pdf');
header('Content-Length: ' . filesize($dir_name . $file));
header('Content-Disposition: 'attachment');
echo $content;
?>

Regards
Dynamo
In article <e4**********@netlx020.civ.utwente.nl>, Rik says...

Dynamo wrote:
Hi,

I am looking for a script that will download a pdf file from my
server without opening it in IE. I want peeople to be able to simply
download the file and store it in a location on their PC. Any help
greatly appreciated.


header('Content-disposition: attachment');

Grtz,


May 23 '06 #3
Rik
Dynamo wrote:
Many thanks but somehow I dont think that snippet of code on its own
will do what I want. I was looking for the complete code. I have
tried the following but it failed miserably. What am I doing wrong?

<?php
$dir_name = "/books/";
$file = "downloadtest.pdf";

$content = file_get_contents($dir_name . $file);

header('Content-Type: pdf');
header('Content-Length: ' . filesize($dir_name . $file));
header('Content-Disposition: 'attachment');
echo $content;

1. Turn on error reporting, if this is you script, it will tell you some
interesting things.
2. Is /books/ in your root? If not, you can't refer to it like this. Does
content indeed hold the file, or just 'false"?

Also:
it's header('Content-type: application/pdf');
The exact syntax is in the php-manual as an example for header...
http://nl3.php.net/en/header

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="name_give_to_user.pdf"');
readfile('/path/to/original.pdf');

Grtz,
--
Rik Wasmus
May 23 '06 #4
Why not just add a note on screen saying something like "User of IE
right-click and then hit 'Save Target As..' to download without opening"

May 23 '06 #5
Good point. I guess it's a matter of personal preference. IMHO I don't think
that looks very professional on a company site. Sure OK for a personal site to
download music etc etc but I don't see many company sites doing that. They
mostly have a "Download here" type of button.

Kind Regards
Dynamo

In article <11**********************@j55g2000cwa.googlegroups .com>, strawberry
says...

Why not just add a note on screen saying something like "User of IE
right-click and then hit 'Save Target As..' to download without opening"


May 23 '06 #6
> Good point. I guess it's a matter of personal preference. IMHO I don't think
that looks very professional on a company site. Sure OK for a personal site to
download music etc etc but I don't see many company sites doing that. They
mostly have a "Download here" type of button.


I would say IT IS more professional to give a "right click to
download"-hint as it it showing the user how to do it right. However a
simple link is more convenient and supports unexperienced users. I
implemented that once with fpdf (fpdf.org). Its method Output() has a
parameter that exactly covers the task (more on
http://www.fpdf.org/en/doc/output.htm). I also remember that I read the
implementation and believe to remember that they worked with some dummy
Content-Disposition. You can either do that as well or create a simple
instance of fpdf and look for the header it sends with with one or the
other option. Try telnet or HTTP Live Headers (Firefox Extension) to see
the headers the server sends.
May 23 '06 #7
Dynamo:
[strawberry:]
Why not just add a note on screen saying something like "User of IE
right-click and then hit 'Save Target As..' to download without opening"


Good point. I guess it's a matter of personal preference. IMHO I don't think
that looks very professional on a company site. Sure OK for a personal site to
download music etc etc but I don't see many company sites doing that. They
mostly have a "Download here" type of button.


If you want to copy a particular website, copy it. Look at what it
says to users, look at what it says to user-agents, send requests, look
at responses.

While strawberry's suggestion would violate the general principle
that says Don't Mention the Mechanics, I regard it as less harmful than
the server-side jiggery-pokery proposed upthread.

--
Jock

May 23 '06 #8
Oops, what have I started...?

May 23 '06 #9
Many thanks. That does exactly what I want. I already looked at that page in the
php manual and the example code is quite a way down the page. Guess I must have
passed it by.

Regards
Dynamo

In article <e4**********@netlx020.civ.utwente.nl>, Rik says...
1. Turn on error reporting, if this is you script, it will tell you some
interesting things.
2. Is /books/ in your root? If not, you can't refer to it like this. Does
content indeed hold the file, or just 'false"?

Also:
it's header('Content-type: application/pdf');
The exact syntax is in the php-manual as an example for header...
http://nl3.php.net/en/header

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="name_give_to_user.pdf"');
readfile('/path/to/original.pdf');

Grtz,


May 24 '06 #10
NC
Dynamo wrote:

I am looking for a script that will download a pdf file from my server
without opening it in IE.


There is no guarantee that this will ever happen. IE ignores
"Content-Dispositoin:" headers completely.

Cheers,
NC

May 24 '06 #11
NC:
IE ignores "Content-Dispositoin:" headers completely.


Given a choice between always ignoring it or always following it, I
think always ignoring it is preferable, not only because it isn't part
of HTTP but also because always following it would grant undue power to
the publisher. But I'd like to think that a user-agent could treat
Content-Disposition as it was intended, as nothing more than a
suggestion. Nothing stops a user-agent from making the publisher's
'desired presentation' - be it the same as or different to the
user-agent's normal mode of presentation - *known* to the user, without
making it obligatory.

</rant>

--
Jock

May 24 '06 #12

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

Similar topics

3
by: Jim J | last post by:
I have been trying to find some kind of authentication method or script (PHP/perl/javascript or other) to achieve the following, with no luck. Say there are 100 files at a site. A person can...
3
by: FLOTServer | last post by:
Here's my problem: I run a gameserver that runs the game "Medal of Honor". On the game server is log file which contains all of the data from the players for that day (kills, deaths, etc...). I...
4
by: Roy | last post by:
Maybe I am in the wrong place and doing this the wrong way... please tell me if you think there is a better way. I need to transfer some files from a server to the client workstation. The...
6
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to...
28
by: Peter Michaux | last post by:
Hi, I'm playing with dynamic script insertion to make a request to the server for a JavaScript file to be automatically run when it arrives in the browser. It works but... The page caching...
1
by: Joey Nolan | last post by:
Hi, I have a PDF file on my site that I want to distribute freely but I want to be able to contact anyone who downloaded it to warn them about mistakes and modification and new versions and...
2
by: Raffi | last post by:
I have a php script which generates a zip file that contains an ASCII text file. The script then prompts the user to save/open the zip file. The script is on a server that is behind an Apache proxy...
4
rajiv07
by: rajiv07 | last post by:
Hi To all, I have a script for downloading file from the server.The Problem is when i try to download WMA file it get download but it is not playing.when i try to play this file in Windows Media...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.