Home > Backend Development > PHP Tutorial > 想问问这段代码为啥不成功

想问问这段代码为啥不成功

WBOY
Release: 2016-06-23 14:28:23
Original
850 people have browsed it

<?php	session_start();	$user = $_SESSION['login_name'];	$filename = $_GET["f"];	$file = "../upload/".$user."/".$filename;	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');	    header('Pragma: public');	    header('Content-Length: ' . filesize($file));	    ob_clean();	    flush();	    readfile($file);	    exit;	}?>
Copy after login


在下载的时候不是弹出下载框,而是直接打印一堆乱码。(估计是readfile直接read到了屏幕上?)
谢谢!


回复讨论(解决方案)

乱码?文件是中文名?

header("Content-type: text/html; charset=GB2312");
或者
header("Content-type: text/html; charset=GBK");

贴出截图!
显然是语法错

贴出截图!
显然是语法错

sorry忘贴图了。
点击这里。其中我点击New Document(2).txt的那个下载链接。跳转到刚刚贴的那段代码里的php:

结果就是浏览器打开了这个txt而不是下载了这个txt。
请问为啥...

ob_clean();flush();
Copy after login
Copy after login

这两个去掉看看

ob_clean();flush();
Copy after login
Copy after login

这两个去掉看看



谢谢!最后是因为我从第二行开始写的 就报错了
看来细节马虎不得!

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