Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 9th, 2009, 05:50 PM
Registered User
Join Date: Feb 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Comparing image file With Blob data

How to compare Image file with the Image(of blob data type) that is retrieved from the MySQL database.????
Old February 21st, 2009, 08:09 PM
Friend of Wrox
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts


When you retrieve the blob it will treat it as a string of unicode characters. Likewise, when you read in a file, it will read in unicode strings and characters. You can therefore do a simple string comparison with == to see if they are the same.
Here is a simple example. Note that it is may be better to stream the file in using fread to save resource, but it is not too hard to implement that.

PHP Code:

$rs mysql_query('SELECT img FROM images WHERE id = 2');
$row mysql_fetch_array($rs);

$image1 $row['img'];
$image2 file_get_contents('mypic.gif');

$image1 == $image2)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing image file With Blob data vipulrb PHP Databases 0 February 9th, 2009 05:49 PM
BLOB: file is empty after retrieving blob data thr taraprasad Pro JSP 0 May 22nd, 2008 10:02 AM
insert image in to oracle blob data type rajesh_bamane Pro VB Databases 3 July 15th, 2006 02:06 AM
How can INSERT Image into BLOB data type shah_shah Pro VB Databases 0 July 6th, 2006 03:51 AM
Problem inserting blob data/uploading file - MySQL kyle_shea Beginning PHP 2 February 15th, 2005 10:18 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.