Help - Search - Member List - Calendar
Full Version: starting a download within php
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
toedipper
Hello,

I want users to be able to download files on my website. The files will
not be located on my site but on some other domain.

I also want to be able to register the download first and then start it
to the user.

I imagine I would have a hyperlink on a page saying 'download here'
This in turn would pass an id number to a page called download.php so
the hyperlink would be "blah blah blah download.php?id=1234" etc.

The download.php would also insert the date and time of the download
into a my sql db.

I can get this far myself but I am stuck now as how to actually then
start the download once I've logged it.

Any ideas?

Thanks,

td.

Fredrik Arild Takle
QUOTE
Any ideas?

First log the download, then:

http://www.php.net/header

Simple example:

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

Best regards
Fredrik A. Takle
Bergen, Norway

Adnan
Hi td,

try something like this.

<?
/*
* Change 'CONTENT=6' to however many seconds
* you want the user to wait to be linked to
* the file
*
* Put this line in between the <head> tags
*/
echo "<META HTTP-EQUIV="refresh" CONTENT="6;
URL=http://link/to/remote_file.zip">";

/*
* put this in the main body after you registered
* the download in the db
*/
echo "Please wait while download starts...";
?>

hope this helps,

adnan


toedipper wrote:
QUOTE
Hello,

I want users to be able to download files on my website.  The files will
not be located on my site but on some other domain.

I also want to be able to register the download first and then start it
to the user.

I imagine I would have a hyperlink on a page saying 'download here' This
in turn would pass an id number to a page called download.php so the
hyperlink would be "blah blah blah download.php?id=1234" etc.

The download.php would also insert the date and time of the download
into a my sql db.

I can get this far myself but I am stuck now as how to actually then
start the download once I've logged it.

Any ideas?

Thanks,

td.


Oli Filth
Adnan said the following on 12/06/2005 12:26:
QUOTE
Hi td,

try something like this.

<?
/*
* Change 'CONTENT=6' to however many seconds
* you want the user to wait to be linked to
* the file
*
* Put this line in between the <head> tags
*/
echo "<META HTTP-EQUIV="refresh" CONTENT="6;
URL=http://link/to/remote_file.zip">";

/*
* put this in the main body after you registered
* the download in the db
*/
echo "Please wait while download starts...";
?


No! Don't do this!

You have no control over the download (because the user now has a direct
URL to the file), it adds an unnecessary 6 (or whatever) second delay,
and it uses "refresh", which isn't a valid HTTP header (although it does
work on many browsers).


--
Oli


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.