Cannot modify header information This problem how to solve, trouble big God moves!
Error: Warning:cannot Modify header Information-headers already sent by (output started at D:\AppServ\www\work\admin\fileu pload_admin.php:49) in D:\AppServ\www\work\conn\conn.php on line 5
I Baidu said can not before the header output anything, my header in the first line, has confirmed that there is no space, but he is an error. Then I looked at the wrong thing is a echo, I write off after he gave an error to the next game echo. The wrong number of lines I have marked in red this file all the functions can be implemented, can be an error, if the header is deleted, the displayed string is garbled, trouble big God moves!
Header ("content-type:text/html; Charset=utf-8 ");
Determine if it is a picture
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"];
Gets the value inside the array
$name = $upfile ["name"];//the filename of the uploaded file
$type = $upfile ["type"];//types of uploaded files
$size = $upfile ["Size"];//upload files
$tmp _name= $upfile ["Tmp_name"];//the temporary storage path of the uploaded file
Determine if it is a picture
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 Upload file name
do{
$newfile = Date ("Ymdhis"). Rand (1000,9999). ".". $fileinfo ["extension"];
}while (File_exists ($path. $newfile));
if ($okType) {
/**
* 0: File Upload successful
* 1: exceeds the file size, set in the php.ini file
* 2: The size of the file exceeds the value specified by the max_file_size option
* 3: Files are only partially uploaded
* 4: No files are uploaded
* 5: Upload file size is 0
*/
$error = $upfile ["Error"];//the value returned by the system after uploading
echo "================
";
echo "Upload file name is:". $name. "
";
echo "Upload file type is:". $type. "
";
echo "Upload file size is:". $size. "
";
echo "The value returned by the system after uploading is:". $error. "
";
echo "The temporary storage path for uploading files is:". $tmp _name. "
";
echo "Start moving the upload file
";
Move the uploaded temporary files to the up directory
Move_uploaded_file ($tmp _name, ' uploads/'. $newfile);
$destination = "uploads/". $newfile;
echo "================
";
echo "Upload message:
";
if ($error ==0) {
echo "File Upload succeeded! ";
echo "
Picture preview:
";
echo "";
echo "alt=\" Picture preview: \ r file name: ". $destination." \ r upload time: \ ">";
}elseif ($error ==1) {
echo "Exceeds file size, set in php.ini file";
}elseif ($error ==2) {
echo "exceeded the file size max_file_size option specified value";
}elseif ($error ==3) {
echo "file is only partially uploaded";
}elseif ($error ==4) {
echo "No files were uploaded";
}else{
echo "Upload file size is 0";
}
}else{
echo "Please upload pictures in jpg,gif,png and other formats!" ";
}
}
Connecting to a database
Include_once ". /conn/conn.php ";
Spelling SQL statements
$sql = "SELECT * from Hs_picname";
Execute SQL statement, return result set
$rst = $conn->execute ($sql) or Die ($conn->errormsg ());
Set a new array
$arr =array ();
Storing the information you want to add in an array
$arr [' imgname ']= $newfile;
$arr [' Idnum ']= $id;
Add statement
$insert = $conn->getinsertsql ($rst, $arr);
Determine if execution is successful
if ($conn->execute ($insert))
{
}
Else
{
echo "";
}
?>
Share to: more
------Solution--------------------
The error message tells you
On line 5th of D:\AppServ\www\work\conn\conn.php
Found output at line 49th of D:\AppServ\www\work\admin\fileupload_admin.php
But you didn't give the two files, or the wrong one.
If this code is D:\AppServ\www\work\admin\fileupload_admin.php,
Then the content of D:\AppServ\www\work\conn\conn.php should be given.
------Solution--------------------
The probable Cause:
1. The file itself contains the BOM header, which causes the output to precede the header function and thus reports an error.
2. Enable other functions that may send headers, such as cookies and session
3. Another file contained may have errors or warning, resulting in the output.
4. The other files included are output (before the header).
Look at you for reasons. It is most likely the reason for the BOM header or the output of other files. (2,3 is unlikely)