如何访问根目录之外的文件并使用它们

时间:2016-07-05 05:31:43

标签: php

首先,我要求道歉,我知道这个问题已被提出并已经得到解答,但我仍然无法弄清楚该怎么做。

我将文件放在根目录之外和之前,并希望在客户购买文件时访问该文件。我知道我可以使用这种方法进行下载,但是我希望这个获取文件并让我将其发送到其他页面,然后客户点击下载链接,并提到客户可能已购买多个文件

如何对所有文件执行相同操作?我应该把它们放在一个循环中吗?

这是我的代码:

<?php
$file = 'monkey.gif';
if (file_exists($file)) 
{
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment;    
    filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-  check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}
?>

提前致谢。

0 个答案:

没有答案