Jump to content

Displaying Multiple images from database


shahrukh1514

Recommended Posts

Hi,

 

I am a student doing a project on Online passport issue through Biometric system using LAMP.

Currently i am stuck at a position where i need to compare images stored in database using BLOB type. I can retrieve the latest image uploaded but that image should be compared with the images in the database. I tried by calling sha1 function but i cant get the result. Below is my code

 

This file is image.php where i can store image in database.

 

<?php

 

// Connect to database

 

$errmsg = "";

if (! mysql_connect("localhost","root","")) {

        $errmsg = "Cannot connect to database";

        }

mysql_select_db("srk");

 

// First run ONLY - need to create table by uncommenting this

// Or with silent @ we can let it fail every sunsequent time ;-)

 

$q = "create table pix (pid int primary key NOT NULL auto_increment, title text, imgdata longblob)";

 

mysql_query($q);

 

// Insert any new image into database

 

if ($_REQUEST[completed] == 1) {

        // Need to add - check for large upload. Otherwise the code

        // will just duplicate old file ;-)

        // ALSO - note that latest.img must be public write and in a

        // live appliaction should be in another (safe!) directory.

        move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");

        $instr = fopen("latest.img","rb");

        $image = addslashes(fread($instr,filesize("latest.img")));

        if (strlen($instr) < 149000) {

                mysql_query ("insert into pix (title, imgdata) values (\"".

                $_REQUEST[whatsit].

                "\", \"".

                $image.

                "\")");

        } else {

                $errmsg = "Too large!";

        }

}

 

// Find out about latest image

 

$gotten = mysql_query("select * from pix order by pid desc limit 1");

if ($row = mysql_fetch_assoc($gotten)) {

        $title = htmlspecialchars($row[title]);

        $bytes = $row[imgdata];

} else {

        $errmsg = "There is no image in the database yet";

        $title = "no database image available";

        // Put up a picture of our training centre

        $instr = fopen("testpic.jpg","rb");

        $bytes = fread($instr,filesize("testpic.jpg"));

}

 

// If this is the image request, send out the image

 

if ($_REQUEST[gim] == 1) {

        header("Content-type: image/jpeg");

        print $bytes;

        exit ();

        }

?>

 

<html><head>

<title>Upload an image to a database</title>

<body bgcolor=white><h2>Here's the latest picture</h2>

<font color=red><?= $errmsg ?></font>

<center><img src=?gim=1 width=144><br>

<b><?= $title ?></center>

<hr>

<h2>Please upload a new picture and title</h2>

<form method="POST" enctype="multipart/form-data">

<input type=hidden name=MAX_FILE_SIZE value=150000>

<input type=hidden name=completed value=1>

Please choose an image to upload:&nbsp&nbsp&nbsp <input type=file name=imagefile ><br>

<p>

Please enter the title of that picture:&nbsp&nbsp <input name=whatsit><br>

</p>

<input type=submit></form><br>

<hr>

</body>

</html>

 

 

Now in this file named compare.php i want to compare the latest uploaded image with that in the database. Assuming there are 10 images in database this latest image should compare itself with all the 10images in database to verify whether that image is already in database.

 

compare.php

 

<?php

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

$con = mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("srk", $con);

 

$result=mysql_query("select imgdata from pix where pid=1");

$row = mysql_fetch_array($result);

$filename01 = $row[imgdata];

header("Content-type: image/jpeg");

echo $filename01;

 

$result2=mysql_query("select imgdata from pix where pid=2");

$row2 = mysql_fetch_array($result2);

$filename02 = $row2[imgdata];

header("Content-type: image/jpeg");

echo $filename02;

 

if (sha1(file_get_contents($filename01)) ==

sha1(file_get_contents($filename02))) {

echo "The files are the same";

echo sha1($filename01);

} else {

echo "The files are not the same";

 

}

?>

 

 

 

since this code only tries to compare two images from database but still it does not execute successfully.

Experts Please help me!!!!!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.