php如何隐藏实际文件地址?这篇文章主要介绍了php隐藏实际地址的文件下载方法,涉及php中header与file_get_contents方法的相关使用技巧。希望对大家有所帮助。
本文实例讲述了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<i>本文@来#源gaodai$ma#com搞$$代**码网</i><strong>搞代gaodaima码</strong>'); 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 文件读取系列方法详解
php 文件分割与合并(断点续传)
PHP 下载 file_put_contents vs readfile
以上就是php隐藏实际文件地址的详细内容,更多请关注搞代码gaodaima其它相关文章!