Home  >  Article  >  Backend Development  >  PHP 隐藏真实上载地址

PHP 隐藏真实上载地址

WBOY
WBOYOriginal
2016-06-13 13:02:26964browse

PHP 隐藏真实下载地址

?

代码:

?

?

<?
	$file_name = "info_check.exe";
	$file_dir = "/public/www/download/";

	//检查文件是否存在
	if(!file_exists($file_dir . $file_name)) exit('文件找不到');
	else 
	{
		$file = fopen($file_dir . $file_name,"r"); // 打开文件

		// 输入文件标签
		Header("Content-type: application/octet-stream");
		Header("Accept-Ranges: bytes");
		Header("Accept-Length: ".filesize($file_dir . $file_name));
		Header("Content-Disposition: attachment; filename=" . $file_name);

		// 输出文件内容
		echo fread($file,filesize($file_dir . $file_name));
		fclose($file);
		exit;
	}
?>
?

而如果文件路径是“http”或者“ftp” 网址的话,则源代码会有少许改变,程序如下:

?

?

<?
	$file_name = "info_check.exe";
	$file_dir = "http://www.easycn.net/";
	$file = @ fopen($file_dir . $file_name,"r");

	if (!$file) exit('文件找不到');
	else {
		Header("Content-type: application/octet-stream");
		Header("Content-Disposition: attachment; filename=" . $file_name);
		while (!feof ($file)) {
			echo fread($file,50000);
		}
		fclose ($file);
	}
?>
?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn