通过PayPal在线销售pdf文件的最佳方式

aka*_*no1 4 php

我只是想知道是否有人可以告诉我通过paypal在线销售pdf文件的正确方法,基本上我使用的是PHP购物车,购物车连接到paypal,只是想知道一旦pdf文件名被添加到购物中购物车并通过paypal支付我如何重定向用户以获取该特定pdf文件或多个文件的下载链接,

任何帮助,将不胜感激,

谢谢

Sil*_*ght 7

你的目标是:

  1. 不要让任何只知道PDF名称的人不付费下载;

  2. 只有在付款后才能下载.

因此,将PDF存储在文档根目录之外,因此没有人可以在浏览器中输入它的名称.例如:

pdf_files/
    1.pdf
    2.pdf
    3.pdf
public_html/
    index.php
    something_else.php
Run Code Online (Sandbox Code Playgroud)

然后,在您的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";
    }
?>
Run Code Online (Sandbox Code Playgroud)