Web lists-archives.com

[PHP] ob_start() -- ob_end_flush() problem




Hi guys:

As many of you know, I teach PHP at my local college. I’ve run into a problem and I can’t find a reason/solution.

Here’s the situation — I use ob_start() --  ob_end_flush() (see below) and my code works.

However, when my students try it, even using my code, it doesn’t work for them.

Now, both my students and I are on the same server with supposedly the same settings — what could go wrong? What should we look for?

Many thanks in advance for those providing their time/expertise to help.

Thank you,

tedd

— here’s the code:

<?php /* display-db-image.php 

    // this script gets an image from an image-field in a db table  
    // and displays the image "as-is" 
     
    /* start buffered output */ 
    ob_start(); 

    $table = 'image_table'; 
             
    $id = isset($_GET['id']) ? $_GET['id'] : 1; 
             
    if(!ctype_digit($id))        // clean -- make sure the $id is a number 
        { 
        $id = 1; 
        } 
         
    include('includes/open-db.php');        //====== open dB 

    $query = "SELECT image FROM $table WHERE id = '$id' "; 
    $result = mysqli_query($conn, $query)  or die("$query  Could not get image"); 

    include('includes/close-db.php');         //====== close dB 

    if(mysqli_num_rows($result) == 1)     
        { 
        $row = mysqli_fetch_assoc($result); 
        $image = $row['image'];     

        // set the header for the image         
        header("Content-type: image/jpeg"); 
        echo($image); 
        } 

    $page = ob_get_contents(); 
    /* end buffered output */ 
    echo($page); 
    ob_end_flush(); 
?>
— end of code

_______________
tedd sperling
tedd@xxxxxxxxxxxx






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php