php隐藏实际地址的文件下载方法

yipeiwu_com5年前PHP代码库

本文实例讲述了php隐藏实际地址的文件下载方法。分享给大家供大家参考。具体如下:

下面这段php代码可不透露实际的文件下载地址。

function download_document($filename,$path="",$mimetype="application/octet-stream")
{
 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
 header("Content-Disposition: attachment; filename = $filename");
 header("Content-Length: " . filesize($pathto . $filename));
 header("Content-Type: $mimetype");
 echo file_get_contents($pathto . $filename);
}

实现方法二:

<?php
$file = "1.txt";// 文件的真实地址(支持url,不过不建议用url)
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;
}
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

Godaddy空间Zend Optimizer升级方法

但今天在安装测试程序的时候提示zend Optimizer not installed.这让我很迷茫,这么普遍的空间为什么没有安装zend了,然后我查看info.php,我惊奇的发现,服...

win7安装php框架Yii的方法

本文讲述了win7安装php框架Yii的方法。分享给大家供大家参考,具体如下: 有人问我win7安装yii老是报错,花了10分钟装了一下,现在做程序的自学能力这么差了?我对框架这些东西不...

PHP面向对象编程快速入门

【摘 要】面向对象编程(OOP)是我们编程的一项基本技能,PHP4对OOP提供了良 好的支持。如何使用OOP的思想来进行PHP的高级编程,对于提高PHP编程能力和&n...

PHP Swoole异步读取、写入文件操作示例

PHP Swoole异步读取、写入文件操作示例

本文实例讲述了PHP Swoole异步读取、写入文件操作。分享给大家供大家参考,具体如下: 异步读取文件:swoole_async_readfile 异步写入文件:swoole_asyn...

php查询ip所在地的方法

本文实例讲述了php查询ip所在地的方法。分享给大家供大家参考。 具体实现方法如下: 复制代码 代码如下:<?php /** *@ date  &n...