The best way to sell pdf files online through paypal
I was 开发者_JS百科just wondering if someone can show me the correct way of selling pdf files online through paypal, Basically I'm using a php shopping cart and the shopping cart connects to paypal, just wondering once the pdf file names have been added to the shopping cart and have been paid through paypal how can I redirect the user to get the download links for that particular pdf file or a multiple of files,
any help would be appreciated,
thanks
Your goals are:
not to let anybody who just knows the name of PDF download it without paying;
make download possible only after payment.
So, store your PDFs outside the document root, so nobody can just type it's name in the browser. For example:
pdf_files/
1.pdf
2.pdf
3.pdf
public_html/
index.php
something_else.php
Then, in your PHP script use direct file output, like this:
<?php
//we are sure that we received the payment
if ($costumer_payed) {
$file_path = '../pdf_files/1.pdf'; //navigating outside the document root!
$file = basename($file_path);
$size = filesize($path);
//headers to show browser that this is a PDF file and that it should be downloaded
header ("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$file");
header("Content-Length: $size");
readfile($file_path); //giving file to costumer
}
echo {
echo "Sorry, pal, pay for your PDF first";
}
?>
精彩评论