473,624 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8352
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.p df";

$content = file_get_conten ts($dir_name . $file);

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

Regards
Dynamo
In article <e4**********@n etlx020.civ.utw ente.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('Conten t-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.p df";

$content = file_get_conten ts($dir_name . $file);

header('Content-Type: pdf');
header('Content-Length: ' . filesize($dir_n ame . $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.pd f"');
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************ **********@j55g 2000cwa.googleg roups.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**********@n etlx020.civ.utw ente.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('Conten t-type: application/pdf');
header('Conten t-Disposition: attachment; filename="name_ give_to_user.pd f"');
readfile('/path/to/original.pdf');

Grtz,


May 24 '06 #10

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

Similar topics

3
1526
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 choose which file to download from a list, and to do so has to enter a code or password. When a valid code or password is used they are redirected to a page with a direct link to download the file. Once that code or password has been used to...
3
15275
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 have a perl script that runs on my webserver, which is supposed to login to the gameserver and download the log. The problem is that when it gets to the part where it needs to download the file, it aborts. The gameserver FTP requires I use port 24...
4
1541
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 transfer has to be initiated from a page served up by the web server. This is easy enough to do with Java Script and Windows FSO but I have to loosen up the browser security and my (military) employer will not allow that. So, is there some way I can...
6
6078
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 parse the filename. <form name='form1' method='POST' enctype='multipart/form-data' action='sub.asp'> <input type='text' name='title1' value='value1'> <input type='file' name='file1'>
28
3418
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 is too good. When I revisit the page or refresh the page, and then redo the script insertion, the browser doesn't even hit the server to check for a newer version of the JavaScript file. The same old script runs with each insertion.
1
2073
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 updates... So I need some way to keep their email addresses and someway to prevent them sharing the link to the PDF file. I've seen some sites - with a form for the user to fill in
2
1866
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 server. Using Firefox, the download works fine and everything goes as intended. However, IE7 tries to download the php script instead of the zip file, resulting in an access error. Below are the pertinent portions of the script. Any help is...
4
2582
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 Player It gives the following error Windows Media Player cannot play the file. The file is either corrupt or the Player does not support the format you are trying to play. Here is My script #!/usr/bin/perl use CGI; use CGI::Carp...
3
5176
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
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5561
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.