【问题标题】:The best way to sell pdf files online through paypal通过贝宝在线销售 pdf 文件的最佳方式
【发布时间】:2011-05-14 13:01:06
【问题描述】:

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

任何帮助将不胜感激,

谢谢

【问题讨论】:

  • 购物车应该能够处理文件下载。你用的是什么购物车?
  • 对不起,我不知道 jcart 并且快速的谷歌搜索没有找到任何关于销售在线材料的文档/论坛实体。

标签: php


【解决方案1】:

你的目标是:

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

【讨论】:

  • 不是 $contents = readfile($file_path);回声$内容; ?
  • @Martin,感谢您的评论。不,readfile 输出文件 - 包含 echo :) 返回值是从文件中读取的字节数。
猜你喜欢
  • 2014-08-27
  • 2012-09-17
  • 2012-11-15
  • 2015-10-07
  • 2012-06-21
  • 1970-01-01
  • 2014-03-28
  • 2010-10-30
  • 1970-01-01
相关资源
最近更新 更多