Jump to content

Recommended Posts

I get the above error, even though I am not echoing anything out.  Is there something int he following code that gets echoed out?  The word "echo" does not appear in this page at all!  It is a page that processes a script so there is no html in it.  No <head>, etc etc.

 

if ($_REQUEST[completed] == 1) {
        move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
        $instr = fopen("latest.img","rb");
        $image = mysql_real_escape_string(fread($instr,filesize("latest.img")));
        if (strlen($instr) < 1000000) {
                mysql_query ("insert into pdf (title, imgdata, category, jl_date, jl_type, description, ref) values ('$title','$image', '$category', '$jl_date', '$jl_type', '$description', '$ref')");

                $_SESSION['errmsg'] = "Done";
        } else {
                $_SESSION['errmsg'] = "Too large!";
        }
} else {
        $_SESSION['errmsg'] = "PDF not uploaded";
}}


header("Location: ".$_SESSION['loc']);

Link to comment
https://forums.phpfreaks.com/topic/268014-cannor-modify-header-information/
Share on other sites

I can't tell if I have any white spaces.  However, in dreamweaver I switched to design view and that page is blank with no characters to delete, so I do not think I have any white spaces.  Are you saying that if I use the space bar when coding, it will come out as a white space?  How can I tell the difference - do I need to scrunch everything together o there are no spaces?

Do you have any white-space before the opening PHP tag? The error should tell you where output was started.

I went back and deleted all quesiton of any white spaces and still get the error.

The error points to line 19 which is this line:

 

if (strlen($instr) < 1000000) {

The error message tells you where the output is sent.

 

Post the exact error.

 

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/e/f/user1234/html/education/add.php:20) in/home/content/j/e/f/user1234/html/education/add.php on line 32

 

Line 32 is the last line of add.php that says header(location etc..

line 20 is the line I specified above as line 19.

 

If you are including another php that may have issues. Usually it is good NOT to close your <?php tags, unless there is more non-php (html). If you do close them and have an unknown space, or new line after it, the file including it will see that as output. If you don't close the tag and have many newlines or spaces the PHP file will ignore those lines.

 

<?php
require_once "some_file.php";  // This will not throw an error
require_once "some_file2.php"; // This will throw an error
header("Content-Type: text/plain");
echo $var;

 

some_file.php

<?php
$var = "some php code";






 

some_file2.php

<?php
$var = "some php code";
?>





 

Hope that makes sense. If that is not the cause are you sure you have valid php?

I'm certain that it's not the only error you have, Jeff, at least not if you have error reporting turned on properly. I suspect that you're also seeing a notice about an undefined constant, which would explain the line numbers in the headers already sent error message.

Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/e/f/user1234/html/education/add.php:20) in/home/content/j/e/f/user1234/html/education/add.php on line 32

 

Line 32 is the last line of add.php that says header(location etc..

 

If you have any html before the header location, it will give that error.

I didn't include the whole file because it didn't contain any output, but here is the entire file.  I can't fnd anything int his file that would give me that error message because there is nothing being echoed out.  here it is:


<?php
session_start();
include "../connectdb.php";
// Store the .pdf

$description = mysql_real_escape_string($_POST['description']);
$category = mysql_real_escape_string($_POST['category']);
$_SESSION['category']=$category;
$title = mysql_real_escape_string($_POST['whatsit']);
$ref = mysql_real_escape_string($_POST['ref']);
$jl_date = mysql_real_escape_string($_POST['jl_date']);
$jl_type = mysql_real_escape_string($_POST['jl_type']);
$jl_type_sub = mysql_real_escape_string($_POST['jl_type_sub']);


if ($_REQUEST[completed] == 1) {
move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = mysql_real_escape_string(fread($instr,filesize("latest.img")));
if (strlen($instr) < 1000000) {
	mysql_query ("insert into pdf (title, imgdata, category, jl_date, jl_type, jl_type_sub, description, ref) values ('$title','$image', '$category', '$jl_date', '$jl_type', '$jl_type_sub', '$description', '$ref')");
	$_SESSION['errmsg'] = "Done";
}
else {
	$_SESSION['errmsg'] = "Too large!";
}
}
else {
$_SESSION['errmsg'] = "PDF not uploaded";
}

header("Location: ".$_SESSION['loc']);

?>

From the link I posted earlier on:

 

Documents encoded in UTF-8 are becoming more and more common. Many programs, however, will add a byte order mark at the very beginning of UTF-8 encoded documents. This appears invisible in the editor and is actually placed before any text you write. This can be a problem when working with PHP scripts. PHP treats the byte order mark as text that needs to be output, and this will happen before it starts executing any PHP code, even if the PHP code appears at the very beginning of the document when viewing it in an editor. Now, the issue here is that you don't get a chance to start output buffering (ob_start()) or call any functions that manipulate the HTTP response headers (session_start(), setcookie(), header() and so on) before the output is started.

 

All of this can be avoided if you make sure that your favorite editor saves your documents without the byte order mark or, alternatively, by enabling output buffering in php.in

 

My bet is your editor is dishing out the Byte Order Mark Check your editor's preferences, or let us know what editor you are using so that you can be assisted to turn it off, re-save and see if that solves your problem.

 

Alternatively, as also mentioned in that topic, you can turn on Output Buffering in Apache which will save all output to the end of execution and should prevent the error from occuring, although that is looked more of a bandaid, it still works.

The output that is occurring on about line 20 of your file - if (strlen($instr) < 1000000) { is because that line is giving a warning message, that you apparently ignored and didn't tell us about -

 

Warning: strlen() expects parameter 1 to be string, resource given in your_file.php on line 20

 

It's not just the last message that you get that is important.

 

You are getting the error on line 20 because $instr is the file handle from the fopen() statement. It is not a string.

Great thanks for that pickup!  I never would have figured that out.  I don't really understand that line, but I guess I will google around and find a better way to upload a file the database.

 

I think this is one option:

 

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx

 

I would not use that code: It's old, severely outdated, and completely insecure!

In addition to that, I would not have saved the files themselves in the database, but directly on the file system; That's what it's meant for, after all. Better to just store the path/filename in the database, and use it to retrieve the file.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.