Jump to content

Recommended Posts

Hello all,

I know there are tons of posts on this everywhere, but none of the solutions people have given in them are working for me.

 

I'm creating a webpage that stores project information, each project can have multiple pictures showing progress. I've made it so that when you click on a project name all of the information on that project is display. Now I need to figure out how to display the pictures that have been uploaded. This is slightly problematic because not only am I displaying other things besides the pictures on the page, I'm also trying to display multiple pictures.

 

Currently, when I try to display the pictures I'm getting binary junk or the alt tag for my images. Everything else displays correctly.

 

The database we are using is phpMyAdmin 3.2.2... I assume that uses MySql, I'm not sure how to find out the version...

The blob is of type mediumblob and has the binary attribute.

The comments table has three fields: project, comment, and picture.

 

Here's my code:

 

<?php

//connect to DB

$pName = $_POST['currProj'];

if($pName != "")
{
    $query = sprintf("select * from `projects` where `name` = '$pName'");
    $result = mysql_query($query);

    // display other information

    $query = sprintf("select * from `comments` where `project` = '$pName'");
    $result = mysql_query($query);

    if(mysql_num_rows($result) >= 1)
    {
        for($i = 0; $i < mysql_num_rows($result); $i++){
            $row =  mysql_fetch_array($result);
            echo " <br /><br /><label>Picture:</label> ";
            $img = base64_decode($row['picture']);
    //        header('Content-type: image/jpeg');    // doing this displays binary/ascii mess
    //        echo $img;                                            //
            echo "<img src=\"getImage.php?count=$i&projName=$pName\" alt=\"error\" />"; // displays 'error'
            echo " <br /><label>Comment:</label> ".$row['comment'];
        }
    }
}

mysql_close($dbh);
?>

 

Code for getImage.php:

<?php
// connect to database

$num = $_GET['count'];
$pName = $_GET['projName'];

if($pName != "")
{
    $query = sprintf("select * from `comments` where `project` = '$pName'");
    $result = mysql_query($query);

    if(mysql_num_rows($result) >= 1)
    {
        for($i = 0; $i < mysql_num_rows($result); $i++){
            if($i == $count){   // only display 1 picture at a time
                $row =  mysql_fetch_array($result);
                $img = base64_decode($row['picture']);
                header('Content-type: image/jpeg');
                echo $img;
            }
        }
    }
}
else
    echo "Unknown project.";

mysql_close($dbh);
?>

 

Suggestions on what I could be doing wrong?

 

Also, apologies if this is in the wrong place.

Link to comment
https://forums.phpfreaks.com/topic/183654-displaying-blob-pictures/
Share on other sites

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.