开发者

Best way to go about storing/accessing PDF Files

Just a quick question (maybe not)

I'm looking to add to my website a way for a customer to login and once logged in they are able to select their invoices which i will upload to my server.

My question is what is the best way to go about storing the files开发者_Go百科 and accessing them. i've done some googling and haven't been able to find much in the way of pointing me in the right direction.

Thanks in advance


Upload them to an unaccessible directory (outside of the www root or protected by htaccess) and serve them with PHP.

This can be done like so:

$file = '/path/to/yourpdf.pdf';

header('Content-type: application/pdf');
header('Content-Length: ' . filesize($file));
readfile($file);

Use PHP and SQL to determine what $file should be and whether or not the user has permission to view the file.


One recommendation I have is to ensure you do not store the actual file in the db. Make sure all you are storing is a pointer (the hyperlink) to a file that is stored somewhere on your network.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜