Home > Backend Development > PHP Tutorial > php下载有关问题,下载后文件内容是空的,图片也没有预览

php下载有关问题,下载后文件内容是空的,图片也没有预览

WBOY
Release: 2016-06-13 12:45:09
Original
744 people have browsed it

php下载问题,下载后文件内容是空的,图片也没有预览
有两个文件,a.php 和 b.php 
点击a.php中的链接,开始对文件下载:代码如下

这是a.php

<br />
<?php <br />
$file_dir = "D:/files";<br />
$file_name = $row[1]; //这是从数据库中查找出来的<br />
echo "<a href='./b.php?file_dir=" . $file_dir . "&file_name=" . $file_name . "'>" . $row[2] . "</a>"; //点击这个链接,下载的文件名是对的,就是文件里没有内容,如果是图片,图片没有预览<br />
?><br />
Copy after login


这是b.php的全部代码
<br />
<?php<br />
	$file_name = $_GET['file_name'];   //文件名<br />
	$file_dir  = $_GET['file_dir'];      //文件路径<br />
	<br />
	if(!file_exists($file_dir.$file_name)){<br />
		 echo "找不到 [" . $file_dir.$file_name . "] 文件";<br />
		 exit;<br />
	}else{<br />
		 $file=fopen($file_dir.$file_name,"r");<br />
	<br />
		Header("Content-type: application/octet-stream");<br />
		Header("Accept-Ranges:bytes");<br />
		Header("Accept-Length:".filesize($file_dir.$file_name));<br />
		Header("Content-Disposition: attachment; filename=".$file_name);<br />
	}<br />
?><br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template