You are here: Re: displaying a file not in the webroot « PHP Programming Language « IT news, forums, messages
Re: displaying a file not in the webroot

Posted by Chuck Anderson on 01/11/08 21:29

firewoodtim@yahoo.com wrote:
> I want to display an uploaded file (e.g. a pdf file) in a "_blank"
> target window. The file is stored outside of the webroot at
> "/home/myhome/uploads/" and was uploaded by a trusted user with the
> function, move_uploaded_file().
>
> I've checked out readfile(), but there is scant info in the way of
> examples on php.net. Can anyone help with some code?
>

header("Cache-Control: cache, must-revalidate");
header("Pragma: public");

header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Length: ' . filesize($file));

// pick one

// to download
// header('Content-Disposition: attachment; filename=' . basename($file));

// to open in browser
// header('Content-Disposition: inline; filename=' . basename($file));

readfile($file);

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Nothing he's got he really needs
Twenty first century schizoid man.
***********************************

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация