Home > Backend Development > PHP Tutorial > (50分)PHP执行遇到 Warning: Cannot modify header information,解决方法

(50分)PHP执行遇到 Warning: Cannot modify header information,解决方法

WBOY
Release: 2016-06-13 10:01:49
Original
932 people have browsed it

(50分求助)PHP执行遇到 Warning: Cannot modify header information,请教大家解决办法
Warning:   Cannot   modify   header   information   -   headers   already   sent   by   (output   started   at   xxxxxx)   in   xxxxx   line   31

code:

if($_GET[ "act "]   ==   "do ")
{
$newdir   =   $dir.$_POST[ "dir "]. "/ ";
$uploadfile   =   $newdir.basename($_FILES[ 'file '][ 'name ']);
//echo   $newdir;
if(move_uploaded_file($_FILES[ 'file '][ 'tmp_name '],   $uploadfile))
{
header( "Location:index.php?dir= ".$_POST[ "dir "]);
}
else
{
die( "上传文件错误 ");
}
}

其中第31行为
header( "Location:index.php?dir= ".$_POST[ "dir "]);

小弟我已经网上寻找解答很久,依旧没有解决办法,请教各位了

------解决方案--------------------
可能UTF保存了 BOM 头...
把文件 用 EditPlus 打开去掉BOM头
------解决方案--------------------
两个解决方法
1.新建个字符编码为 utf-8 的文件把文件内容复制进去-> 保存!
我是这么想的,大概在修改文件的字符编码的时候,文件不被显示的header部分被修改了,导致以上错误!
2.如johnpanq(飞花逐月)所回答!
为了方便你可以将js脚本写入你的自定义函数库
以后直接调用就可以了,因为header问题确实很麻烦!
------解决方案--------------------
少了个"号
应该是:
echo ' ';

你的BOM头,可能在所有的文件中都存在,而不只是一个文件.

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