<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.
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
--
You could start a session on the previous page, and store $file in
there...
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
> 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
<?
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