PHP Classes

Image Not Displayed

Recommend this page to a friend!

      Shref Image in DB  >  All threads  >  Image Not Displayed  >  (Un) Subscribe thread alerts  
Subject:Image Not Displayed
Summary:Blank HTML document when trying to display using this class
Messages:9
Author:Rupe Billions
Date:2006-10-21 13:32:44
Update:2006-10-25 17:14:08
 

  1. Image Not Displayed   Reply   Report abuse  
Picture of Rupe Billions Rupe Billions - 2006-10-21 13:32:44
I used the adding.img.to.db.php and geting.image.from.db.php for this class using my own database and your image. I get a completely blank page with no code. In phpMyAdmin the database looks like it contains what it should.

Please help me.

  2. Re: Image Not Displayed   Reply   Report abuse  
Picture of Ahmed Shreef Ahmed Shreef - 2006-10-21 15:07:13 - In reply to message 1 from Rupe Billions
Hi Rupe,
maybe there is a hidden error, add "error_reporting(E_ALL);" at the start of the file. this will show any hidden error.
also after adding the image in your database, open phpMyAdmin and make sure that the column where the image is saved, isn't empty.

thank you

  3. Re: Image Not Displayed   Reply   Report abuse  
Picture of Rupe Billions Rupe Billions - 2006-10-21 15:30:01 - In reply to message 2 from Ahmed Shreef
Thanks for your quik reply. Which file should I place the error checking statement in. I tried it in geting.image.from.db.php and still get the same relult. I checked the database in phpmyadmin and the field contains the image.

  4. Re: Image Not Displayed   Reply   Report abuse  
Picture of Ahmed Shreef Ahmed Shreef - 2006-10-21 22:55:59 - In reply to message 3 from Rupe Billions
I don't know, my tests didn't report any errors.
check this on your server and tell me what you got.

[code]

<?php

//declare this variables
$dbName = 'your Db name';
$tableName = 'table name';
$imageField = 'image column';
$idField = 'id column';
$idNum = 'id of image';


$con = mysql_connect('localhost','root','');
mysql_select_db($dbName) or die("couldn't connect");

$dbQuery = "SELECT ".$imageField.
" FROM ".$tableName.
" WHERE ".$idField." = ".$idNum.
" LIMIT 1" ;

if ($result = mysql_query($dbQuery) )
{
$row = mysql_fetch_assoc($result);

$char = explode(" ",$row[$imageField]);

header('content-type: image/gif');
$image = "";
foreach($char as $key=>$value)
{
$image .=chr($value) ;
} //foreach
print $image;
}
else
{
print 'failed to query the DB';
}

[/code]

  5. Re: Image Not Displayed   Reply   Report abuse  
Picture of Rupe Billions Rupe Billions - 2006-10-21 23:32:00 - In reply to message 4 from Ahmed Shreef
I carefully entered the information for the following:

$dbName = 'main';
$tableName = 'people';
$imageField = 'Photo';
$idField = 'ID';
$idNum = '2';

and changed the mysqlconnect line to:

$con = mysql_connect('mysql5.server320.com','unitedem','*******');

(I entered my correct password instead on the *******)

I got the same blank result as before. The page has no statement when I do view source and nothing is displayed.

- Rupe


  6. Re: Image Not Displayed   Reply   Report abuse  
Picture of Ahmed Shreef Ahmed Shreef - 2006-10-22 09:37:16 - In reply to message 5 from Rupe Billions
mmm, try adding the image again in the db. you can try any gif image else.
then try the code in my last replay.
if this don't display any thing so maybe you have a problem when inserting the image.
also make sure that the image column is of type "Blob".

  7. Re: Image Not Displayed   Reply   Report abuse  
Picture of Rupe Billions Rupe Billions - 2006-10-22 18:18:05 - In reply to message 6 from Ahmed Shreef
Thanks again. My hosting service also cannot determine what is wrong. They suggest that I look at the binary data in detail, but I am not sure what to do.

Another approach that I would like to consider is to store the file name of the image in a field and then use that to display the image stored in a file. I do not know how to retrieve the file name and use that to dispaly the image. Do you know how to do that?

  8. Re: Image Not Displayed   Reply   Report abuse  
Picture of Ahmed Shreef Ahmed Shreef - 2006-10-22 23:06:28 - In reply to message 7 from Rupe Billions
this approach isn't supported by this class. but you can do it simply.
see this SQL query :
[code]
SELECT ImageName From table_name
WHERE UserID = "your user id variable"
LIMIT 1;
[/code]
I have got the name of the image from the DB depending on the user id. now I will fetch the data and display the image in a html file.

[code]
$data = mysql_fetch_assoc( ... );

print '<img src="images/' . $data['imageName'] . '" />' ;
[/code]

that's every thing, just modify it to fit in your scenario.

Best Regards,
Ahmed Shreef

  9. Re: Image Not Displayed   Reply   Report abuse  
Picture of Rupe Billions Rupe Billions - 2006-10-25 17:14:08 - In reply to message 4 from Ahmed Shreef
Would you mind testing the code below on your computer? I now get more than a blank page, but I get the box with an X in it to signify that the image could not be found. I ask you to keep the login info confidential. This code should display linux.gif which I copied from your site and then uploaded using PhpMyAdmin. I appreciate your help.


<?php

//declare this variables
$dbName = 'main';
$tableName = 'people';
$imageField = 'Photo';
$idField = 'ID';
$idNum = '1';


$con = mysql_connect('mysql5.server320.com','unitedem','rooster');
mysql_select_db($dbName) or die("couldn't connect");

$dbQuery = "SELECT ".$imageField.
" FROM ".$tableName.
" WHERE ".$idField." = ".$idNum.
" LIMIT 1" ;

if ($result = mysql_query($dbQuery) )
{
$row = mysql_fetch_assoc($result);

$char = explode(" ",$row[$imageField]);

header('content-type: image/gif');
$image = "";
foreach($char as $key=>$value)
{
$image .=chr($value) ;
} //foreach
print $image;
}
else
{
print 'failed to query the DB';
}