note all image store in database . long blob.

so i have a gallery.php page where i have all the image of user who i loged in.
echo" <a href='zoom.php'><img src=\"$src\" width='130px' height='130px' class='image_p' /></a>";

now i want to make a zoom.php page. here i want to display the same image what user click in gallery.php.
but i dont know how to do that. any ideas?

Member Avatar
diafol

How about:

$urlsrc = rawurlencode($src);
echo "<a href='zoom.php?img=$urlsrc'><img src=\"$src\" width='130px' height='130px' class='image_p' /></a>";

Then in your zoom.php page:

if(isset($_GET['img'])){
    //process the get info to retrieve the img, using rawurldecode() to get the image url
}

i am store images in database type long blob. iam not sure how can i get

//process the get info to retrieve the img, using rawurldecode() to get the image url

Member Avatar
diafol

OK, in this case, I'd use an ID for the url. You're obviously retrieving the filename from the DB, so retrieve the ID (primary key too) - let's call it $id for now.

echo "<a href='zoom.php?img=$id'><img src=\"$src\" width='130px' height='130px' class='image_p' /></a>";

So no need for encode/decode if just passing an integer.

if(isset($_POST['id'])){
    //retrieve record (row) from db with $_POST['id']
    //remember to clean the variable before using in a query
    header("Content-type: image/jpg");
    echo $row['photoblob'];
}

This is very simplistic - you'll need to add error handling, content-type specifics for the image type maybe.

but isnt img=$id is equal to user_id?
i have on top $id = $_SESSION['user_id'];

Member Avatar
diafol

but isnt img=$id is equal to user_id?

How should I know?!

Call it something else then. Whatever works for you. You have not provided any info with regard to the database table nor said anything about the context of the use to which this is being put. E.g. are these images avatars or profil pictures - in which case there may be ONE per user, or if you have related tables, an user may have multiple avatars which have an 'active' flag. If you need further assistance with this issue, provide more information including the context.

profile pics not avatars.

better?

gallery.php
<?php
include("include/header.php");


if(isset($_SESSION['username']))  //is user is loged in 
{       
    $user = $_SESSION['username'];
    $id = $_SESSION['user_id'];    //get user_id who ever is loged in

    //select images from database   
    $result = mysql_query("SELECT * FROM image WHERE user_id = $id ORDER BY image_id DESC");

    $count = 0;

    echo "
        <head>
            <link rel='stylesheet' type='text/css' href='css/top_menu.css' />
            <link rel='stylesheet' type='text/css' href='css/all_css.css' />
        </head>
        <div id ='bg4'>
            <div id='context4'>

            <table width='1000px' cellpadding='45px'>                      
                <tr>";  
                    while($row = mysql_fetch_assoc($result))
                        {
                            $image_short_name_r = $row['image_short_name'];
                            echo"<td>";
                                $image_db = $row['image'];
                                $src = "data:image/gif;base64," . $image_db;
                                echo" <a href='zoom.php?img='$id'><img src=\"$src\" width='130px' height='130px' class='image_p' /></a>";
                                echo "<center id='image_name'><a href='zoom.php'>" . $image_short_name_r . "</a></center>";
                            echo"</td>";
                                $count++;
                                if($count == 5)       //5 rows
                                {
                                    echo "</tr><tr>"; // Start a new row at 6 cells
                                    $count = 0;
                                }
                            }
                    echo "
                    </tr>
                </table>
            </div>
        </div>   
        ";
}
Member Avatar
diafol

You've got this:

$result = mysql_query("SELECT * FROM image WHERE user_id = $id ORDER BY image_id DESC");

So you use the $row['image_id'] here

echo "<a href=\"zoom.php?img={$row['user_id']}\"><img src=\"$src\" width='130px' height='130px' class='image_p' /></a>";

and to print image in zoom.php i do some thing like this?

$queryget = mysql_query("SELECT image FROM image");
                    $row = mysql_fetch_assoc($queryget);    
                    $image_db = $row['image_'];
                    $src = "data:image/gif;base64," . $image_db;
                    echo"<img src=\"$src\" height = '70%' width='70%' class='image_p' />";




           this is print same image.

$image_id = $_GET['img'];

                //get image from database
                $queryget = mysql_query("SELECT image FROM image WHERE image_id = $image_id");
                $row = mysql_fetch_assoc($queryget);    
                $image_db = $row['image'];
                $src = "data:image/gif;base64," . $image_db;