Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
安全直接文件下载器PHP需要修复_Php - Fatal编程技术网

安全直接文件下载器PHP需要修复

安全直接文件下载器PHP需要修复,php,Php,不幸的是,这段代码不起作用,因为我想通过php下载文件,需要隐藏上传到服务器上的文件的直接路径 如果我在变量中定义完整路径example.com/files/filedownload.iso那么它可以工作,但毫无意义,因为我想在下载时隐藏路径 <form target="_blank" id="download_file" action="download.php" method="post"> <input name="ip" type="hidden" value="192

不幸的是,这段代码不起作用,因为我想通过php下载文件,需要隐藏上传到服务器上的文件的直接路径

如果我在变量中定义完整路径example.com/files/filedownload.iso那么它可以工作,但毫无意义,因为我想在下载时隐藏路径

<form target="_blank" id="download_file" action="download.php" method="post">
<input name="ip" type="hidden" value="192.123.23.1">
<input name="filename" type="hidden" value="filedownload.iso"'; ?>
<div align="center">
<input alt="Submit" src="download.gif" type="image" />
</div>
</form>


我不确定这是否适用于您,也不适用于大文件,但如果您将用户重定向到带有此代码的页面,它将以二进制格式将文件流式传输到他们的系统。如果你的文件太大,这样做行不通,不要成为一个憎恨者:)

顺便说一句,我很想为此获得荣誉,我搜索了资料来源(找不到),但几年前,在别人的建议下,这击中了我的图书馆

$nameFile = 'insert just name of file here'
$pathFile = 'insert file and path here';
$sizeFile = filesize($pathFile);
$pointerFile = fopen($pathFile, "rb"); // Open file for reading in binary mode
$contentFile = fread($pointerFile, $sizeFile);
fclose($pointerFile);

header("Content-length: ".$sizeFile);
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=".$nameFile.";" );
echo $contentFile;

如果使用任何类型的重定向,浏览器中的F12开发者工具将向任何人显示文件的确切位置。您需要使用类似PHP的文件内容。你给用户的页面不需要包含文件夹甚至文件名,一个ID就足够了。我雇了人来做这件事!但我的apache在获得一些流量后似乎崩溃了!以上方法是我想尝试的另一种方法!
$nameFile = 'insert just name of file here'
$pathFile = 'insert file and path here';
$sizeFile = filesize($pathFile);
$pointerFile = fopen($pathFile, "rb"); // Open file for reading in binary mode
$contentFile = fread($pointerFile, $sizeFile);
fclose($pointerFile);

header("Content-length: ".$sizeFile);
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=".$nameFile.";" );
echo $contentFile;