[TYPO3-english] server file as download

Zachary Vineyard ZVineyard at NNU.Edu
Mon Feb 16 17:34:45 CET 2009


Hi Goran,

Here's a quick example of a PDF downloader.

--?php
$actual_name = $_GET['d'];
$file = 'http://example.com/files/' . $_GET['d']; 
if(!file($file))
{
     // File doesn't exist, output error
     die('file not found');
}
 else
{
     // Set Headers
     header("Pragma: public");
	 header("Expires: 0"); // set expiration time
	 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Content-Description: File Transfer");
     header("Content-Disposition: attachment; filename=$actual_name");
	 // Force Download
	 header("Content-Type: application/force-download");
	 header("Content-Type: application/octet-stream");
	 header("Content-Type: application/download");
     // Read the file from disk
     readfile($file);
}
?--

This will only display the file name to users, not the directory. I just point the user to something like: 

http://www.example.com/download.php?d=filename.pdf

Make sure you change the URL around line 3.


All Best,
 
Zac
 


>>> "Goran Liczic" <goranli at mail.hu> 2/16/2009 9:21 AM >>>
Hi all,

I want to server pdf files from a certain directory as download. They should not open in acrobat, but a downloadbox should appear.

The filename of the downloaded file should just be the fiolename *without* pathname.
Also no filepath should appear. neither in http headers not when doanloading the file.

Anyone any suggestions for this task in php?

Thanks
Goran

_______________________________________________
TYPO3-english mailing list
TYPO3-english at lists.netfielders.de 
http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-english



More information about the TYPO3-english mailing list