(50 points) PHP Execution Encounters Warning:cannot Modify header information, workaround

Source: Internet
Author: User
(50 points for help) PHP execution encountered warning:cannot modify header information, ask everyone to solve the solution
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 ("Upload file error");
}
}

where the 31st Act
Header ("location:index.php?dir=". $_post["dir"]);

I have been searching the internet for a long time, still no solution, ask you

------Solution--------------------
The BOM header may have been saved by UTF ...
Open the file with EditPlus and remove the BOM header.
------Solution--------------------
Two Solutions
1. Create a file with characters encoded as Utf-8 copy the contents of the file and save it!
I think so, probably in the modification of the character encoding of the file, the file is not displayed in the header section has been modified, resulting in the above error!
2. As Johnpanq (fly monthly) answer!
For your convenience you can write a JS script to your custom function library
Call directly later on, because the header problem is really troublesome!
------Solution--------------------
There's a "number missing."
Should be:
Echo ';

Your BOM header may exist in all files, not just a file.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.