Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-27-2012, 11:20 PM   PM User | #1
Maize
New to the CF scene

 
Join Date: Jan 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Maize is an unknown quantity at this point
File download security?

I'm assuming that providing a public link to a pdf file on our server, for example, example.com/files/etc/downloadme.pdf, isn't exactly secure. Am I right?

Is the best way to implement this is to pass in some parameters that the server will analyze, get the pdf file, and return a stream? I've been searching for some tutorials but can't seem to find any.

Thanks.
Maize is offline   Reply With Quote
Old 04-27-2012, 11:42 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,455
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
If you want to limit access then put the pdfs above your public_html and access them via a script. You can add whatever validation in front of the following (which assumes that the name of the PDF file is in $pdf

Code:
ini_set('zlib.output_compression','Off');
header("Pragma: public");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: must-revalidate");
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="'.$pdf.'"');
header('Content-Length: ' . filesize("../$pdf"));
readfile("../$pdf");

replace attachment with inline if you want the PDF to display in the page instead of being downloaded outside the browser.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 04-28-2012, 01:09 AM   PM User | #3
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
Quote:
Originally Posted by Maize View Post
I'm assuming that providing a public link to a pdf file on our server, for example, example.com/files/etc/downloadme.pdf, isn't exactly secure. Am I right?
Not at all. What leads you to believe it might not be secure? You would not be storing it in the directory you used in your example but if it's for public consumption, putting in a directory your web server can "see" and providing a link to it is just fine.
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:03 PM.


Advertisement
Log in to turn off these ads.