2010-11-23 64 views
4

我只是想知道如果有人能告诉我通过PayPal在线销售PDF文件的正确方式, 基本上我使用的是PHP购物车,购物车连接到贝宝,只是想知道一旦PDF文件名已被添加到购物车,并已通过贝宝支付如何重定向用户获得该特定的PDF文件或多个文件的下载链接,通过PayPal在线销售PDF文件的最佳方式

任何帮助将请注意,

谢谢

+0

,购物车应该能够处理文件下载。你在用什么购物车? – Martin 2010-11-23 15:27:49

+0

我正在使用jcart – amir 2010-11-23 15:36:03

回答

7

您的目标是:

  1. 不让任何人知道PDF的名称只需下载它就可以免费下载;

  2. 使下载成为可能后付款。

因此,将您的PDF存储在文档根目录之外,这样任何人都不能在浏览器中输入它的名称。例如:

pdf_files/ 
    1.pdf 
    2.pdf 
    3.pdf 
public_html/ 
    index.php 
    something_else.php 

然后,在你的PHP脚本中使用直接文件输出,这样的:

<?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"; 
    } 
?>