0

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?

Edited by hwoarang69

2
Contributors
10
Replies
11
Views
5 Years
Discussion Span
Last Post by hwoarang69
Featured Replies
  • 1
    diafol 3,669   5 Years Ago

    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 } Read More

  • 1
    diafol 3,669   5 Years Ago

    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 … Read More

  • 1
    diafol 3,669   5 Years Ago

    > 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 … Read More

  • 1
    diafol 3,669   5 Years Ago

    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>"; Read More

1

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
}
0

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

1

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.

0

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

1

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.

0

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>   
        ";
}

Edited by hwoarang69

1

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>";
0

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.

Edited by hwoarang69

0

$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;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.