Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to hide the url of a file for download

0 views
Skip to first unread message

_andrea.l

unread,
Jul 1, 2005, 3:59:43 AM7/1/05
to
I'd like to let user download a file but I'd like to hide the url of the
file.
I'd like to write something like that:

<a href="download_file.php?id=1123">download file</a>

download_file.php get the file and give it to user.
BUT...
... how can I write download_file.php?
thank you in advance for your help,
Andrea.


Alvaro G Vicario

unread,
Jul 1, 2005, 4:23:08 AM7/1/05
to
*** _andrea.l wrote/escribió (Fri, 01 Jul 2005 07:59:43 GMT):
> I'd like to let user download a file but I'd like to hide the url of the
> file.

Downloading a file from a hidden URL is like calling someone whose phone
number is unknown...


> ... how can I write download_file.php?

Given that what you really want to know is how to write a download script,
I've found this example in the manual page for header():


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


It shouldn't be difficult to write a generalization.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--

Tim Van Wassenhove

unread,
Jul 1, 2005, 4:43:45 AM7/1/05
to

You could start a session on the previous page, and store $file in
there...

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>

John Dunlop

unread,
Jul 1, 2005, 9:57:13 AM7/1/05
to
_andrea.l wrote:

> I'd like to let user download a file but I'd like to hide the url of the
> file.

Are you positive all your visitors are up for a game of hide
and seek, _andrea.1?

--
Jock

BKDotCom

unread,
Jul 1, 2005, 10:27:54 AM7/1/05
to
restrict the download to a "logged in" user?

Dave Turner

unread,
Jul 1, 2005, 12:35:00 PM7/1/05
to
download.php ...

<?
set_time_limit(600); // 600 secs (10 mins) maximum transfer

$fname = $_GET["fname"];

switch(trim(strtolower($fname)))
{
case 'myfile1':
$file = 'private/file1.zip'; break;
case 'myfile2':
$file = 'private/file2.zip'; break;
default:
Location("downloadinvalid.php"); exit;
}

header ("Pragma: no-cache"); // HTTP/1.0
header('Content-Description: File Transfer\n');
header("Content-type: application/octect-stream\n");
header('Content-Length: ' . filesize($file) . "\n");
header('Content-Transfer-Encoding: binary\n');
header('Content-Disposition: attachment; filename=' . basename($file) .
"\n\n");
readfile($file);
?>


usage:
download.php?fname=myfile1

0 new messages