PHP的header警告

来源:互联网 发布:把淘宝链接转换成文字 编辑:程序博客网 时间:2024/05/16 18:22

今天在学习PHP视频时,写的下载文件的程序总是报警告,且功能没有出来。

代码如下

<?php$file_name = "file.jpg";if ( !file_exists($file_name)) {echo "file not exist !";return ;}$fp = fopen($file_name, "rb");$file_size = filesize($file_name);header("Content-type: application/octet-stream");header("Accept-Ranges: bytes");header("Accept-Length: $file_size");header("Content-Disposition: attachment ; filename=".$file_name);$buffer = 1024;$read_data = "";while (!feof($fp)) {$read_data .= fread($fp, $buffer);}echo $read_data;fclose($fp);?>

警告如下

Warning: Cannot modify header information - headers already sent by (output started at D:\Web\AppServ\www\exe\downfile\down.php:1) inD:\Web\AppServ\www\exe\downfile\down.php on line 11

Warning


Warning
: Cannot modify header information - headers already sent by (output started at D:\Web\AppServ\www\exe\downfile\down.php:1) inD:\Web\AppServ\www\exe\downfile\down.php on line 12

Warning
: Cannot modify header information - headers already sent by (output started at D:\Web\AppServ\www\exe\downfile\down.php:1) inD:\Web\AppServ\www\exe\downfile\down.php on line 13

Warning: Cannot modify header information - headers already sent by (output started at D:\Web\AppServ\www\exe\downfile\down.php:1) inD:\Web\AppServ\www\exe\downfile\down.php on line 14


经过网上查找资料,并试过几种方法,最后用http://www.zreading.cn/ican/2012/01/wordpress-warning-cannot-modify-header-information-headers-already-sent-by/的方法得以解决,其实就是编码的问题,用“格式”->“以ANSI格式编码"即可,在此,谢谢这位朋友。

0 0