How can we solve the Cannotmodifyheaderinformation problem?

Source: Internet
Author: User
How can we solve the Cannotmodifyheaderinformation problem! Error: Warning: & nbsp; Cannot & nbsp; modify & nbsp; header & nbsp; information & nbsp;-& nbsp; headers & nbsp; already & nbsp; how to solve the se Cannot modify header information problem!
Error: Warning: Cannot modify header information-headers already sent by (output started at D: \ AppServ \ www \ work \ admin \ fileupload_admin.php: 49) in D: \ AppServ \ www \ work \ conn. php on line 5
I told Baidu that I couldn't output anything before the header. my header was in the first line and confirmed that there was no space, but he reported an error. Then I read the wrong echo. After I deregistered it, he reported an error in the next echo. The number of wrong lines can be achieved by marking all the functions in this file in red, but an error is reported. if you delete the header, the displayed strings are garbled, so please try again!

Header ("Content-type: text/html; charset = utf-8 ");
// Determine whether the image is used
Switch ($ type ){
Case 'image/pjpeg ': $ okType = true;
Break;
Case 'image/jpeg ': $ okType = true;
Break;
Case 'image/GIF': $ okType = true;
Break;
Case 'image/png ': $ okType = true;
Break;
}

$ Id = $ _ POST [id];
// Print_r ($ _ FILES ["upfile"]);
If (is_uploaded_file ($ _ FILES ['upfile'] ['tmp _ name']) {
$ Upfile = $ _ FILES ["upfile"];
// Obtain the values in the array
$ Name = $ upfile ["name"]; // file name to be uploaded
$ Type = $ upfile ["type"]; // file Upload type
$ Size = $ upfile ["size"]; // size of the uploaded file
$ Tmp_name = $ upfile ["tmp_name"]; // temporary storage path for uploaded files
// Determine whether the image is used
Switch ($ type ){
Case 'image/pjpeg ': $ okType = true;
Break;
Case 'image/jpeg ': $ okType = true;
Break;
Case 'image/GIF': $ okType = true;
Break;
Case 'image/png ': $ okType = true;
Break;
}
$ Fileinfo = pathinfo ($ name); // Parse the name of the uploaded file
Do {
$ Newfile = date ("YmdHis"). rand (1000,9999). ".". $ fileinfo ["extension"];
} While (file_exists ($ path. $ newfile ));
If ($ okType ){
/**
* 0: The file is uploaded successfully.
 
* 1: The file size is exceeded. set it in the php. ini file.
 
* 2: The file size exceeds the value specified by the MAX_FILE_SIZE option.
 
* 3: only part of the file is uploaded.
 
* 4: no files are uploaded.
 
* 5: The size of the uploaded file is 0.
*/
$ Error = $ upfile ["error"]; // value returned by the system after uploading
Echo "========================
";
Echo "the name of the uploaded file is:". $ name ."
";
Echo "the Upload file type is:". $ type ."
";
Echo "the size of the uploaded file is:". $ size ."
";
Echo "the value returned by the system after the upload is:". $ error ."
";
Echo "the temporary storage path for uploaded files is:". $ tmp_name ."
";

Echo "start to move and upload files
";
// Move the uploaded temporary file to the up Directory
Move_uploaded_file ($ tmp_name, 'uploads/'. $ newfile );
$ Destination = "uploads/". $ newfile;
Echo "========================
";
Echo "upload information:
";
If ($ error = 0 ){
Echo "the file has been uploaded successfully! ";
Echo"
Image preview:
";
Echo "";

// Echo "alt = \" image preview: \ r File name: ". $ destination." \ r Upload Time: \ "> ";
} Elseif ($ error = 1 ){
Echo "exceeds the file size and is set in the php. ini file ";
} Elseif ($ error = 2 ){
Echo "exceeds the file size specified by the MAX_FILE_SIZE option ";
} Elseif ($ error = 3 ){
Echo "only part of the file is uploaded ";
} Elseif ($ error = 4 ){
Echo "no file is uploaded ";
} Else {
Echo "the size of the uploaded file is 0 ";
}
} Else {
Echo "please upload images in jpg, gif, png, and other formats! ";
}
}

// Connect to the database
Include_once "../conn. php ";
// Spell an SQL statement
$ SQL = "select * from hs_picname ";
// Execute the SQL statement and return the result set
$ Rst = $ conn-> execute ($ SQL) or die ($ conn-> errorMsg ());
// Define a new array
$ Arr = array ();
// Save the information to be added to the array
$ Arr ['imgname'] = $ newfile;
$ Arr ['idnum'] = $ id;
// Add a statement
$ Insert = $ conn-> getInsertSQL ($ rst, $ arr );
// Determine whether the execution is successful
If ($ conn-> execute ($ insert ))
{
}
Else
{
Echo "script alert ('upload failed! '); History. back () script ";
}
?> Share: More

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.