22, November 2008

problems with displaying BLOB info from a database - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: problems with displaying BLOB info from a database
« previous next »
Pages: [1] Print

Author Topic: problems with displaying BLOB info from a database  (Read 830 times)
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« on: May 03, 2007, 11:50:54 PM »

I have read many articles on this and have tried changing some code but can only get what the images would be in text character format...so I think I am partially there. name, type, size, content are my rows in the database and the BLOB info is stored in content

From one of the articles I read...getimage.php would do the following (the part I am having problems with is mainly step 1.)
1. Get the BLOB content into a var ($content would be the var)
2. Send the Content-Type: image/gif (jpg or png depending on the type) use a header for this
3. Output the blob content with a print $blob print or echo <?php echo $content; ?>

then the actual image display page would link like <img src="/getimage.php?id=23"> where 23 is the id which contains the BLOB info.

I get how to link with the getimage.php and var, but not how to convert the BLOB info into an image.

I have code that I can post, but I didn't want to make this too long of a post.  Any help would be appreciated and I can post some snippets if you would like.

aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #1 on: May 04, 2007, 01:35:10 AM »

This is a modified version of something i found in the php.net manual. Does this help?

Code:
<?php
// create a 100*30 image
$im imagecreate(10030);

// white background and blue text
$bg imagecolorallocate($im255255255);
$textcolor imagecolorallocate($im00255);

// write the string at the top left
imagestring($im500"Hello world!"$textcolor);

// output the image
header("Content-type: image/png");
imagepng($im);
?>

Output:

Instead of "Hello World!" , i would assume you would just change that to the $content variable.



Source: Yahoo! Search "create image from text php", result chosen: "#1"
« Last Edit: May 04, 2007, 01:37:14 AM by Meth0d »

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« Reply #2 on: May 04, 2007, 07:16:00 AM »

Thank you for your reply MethOd.  I tried several things with that code, and didn't have any success.  It does look very interesting though like the output being the way that it is...it would be nice if you could echo fonts that aren't available on a users computer....Shocked

As far as the pics being displayed...when I did my searches as you might imagine there were pages and pages of different methods and a lot seemed to be incomplete or not very efficient, and I couldn't get anything to work.  I FINALLY got one to work properly and here is the code in case someone wants to test it out on their own.  It is only one file which makes it nice.

CREATE DATABASE
Code:
CREATE TABLE `tbl_image` (
  `id` int(11) NOT NULL auto_increment,
  `image` blob NOT NULL,
  `type` varchar(30) NOT NULL,
  PRIMARY KEY  (`id`)
);

Just create a folder named "tmp" and chmod to 777 or you will get the Could not copy error.

Code:
<?php //  image.php
$cn mysql_connect("localhost","username","password");
mysql_select_db("db_name",$cn);

if ($act=='view'){
$sql="SELECT * FROM tbl_image where id=$id";
$rst=mysql_query($sql) or die('gagal');
$data=mysql_fetch_array($rst);
$type=$data[type];
Header("Content-type: $type");
echo $data[image];
}

if ($act=='del'){
$sql="DELETE FROM tbl_image where id=$id";
$rst=mysql_query($sql) or die('gagal');
}

if(
$submit)
{
    
$type $_FILES['file']['type'];
copy ($_FILES['file']['tmp_name'], "tmp/tmp.jpg") or die ("Could not copy");
$filer="tmp/tmp.jpg";
    
$handle fopen($filer"r");
$pure addslashes(fread($handlefilesize($filer)));
$sql  "insert into tbl_image(image,type) values('$pure','$type')";
    
$result mysql_query($sql,$cn)or die(mysql_error());
}

$sql="SELECT * FROM tbl_image";
$rst=mysql_query($sql) or die('gagal');
while ($data=mysql_fetch_array($rst)){
$id=$data[id];
echo "picture no $id <a href='./image.php?act=del&id=$id'>delete</a><br><img src='./image.php?act=view&id=$id'><br><br>";
}

?>

<html>
<head>
<title>upload image</title>
</head>
<body>
<form action='image.php' method='post' enctype="multipart/form-data">
<input type='file' name='file'>
<input type='submit' name='submit'>
</form>
</body>
</html>

Thank you,
Brad
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6440
39464 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: May 04, 2007, 07:34:08 AM »

why using the blob data as image? this will generate a big server load if the site becomes busy...


Last blog : Just a better Internet portal provided by Google
aka J Love
Community Supporter ?
Bill Gates is my home boy
*****
Gender: Male
Posts: 884
1636 credits
Members referred : 4



« Reply #4 on: May 04, 2007, 10:11:03 AM »

why using the blob data as image? this will generate a big server load if the site becomes busy...

i was going to warn of something similair.. being that blob can be a *LOT* of data, creating a huge image.. but i tried to give the solution he was seeking Wink

Visit through proxy Visit through proxy Visit through proxy

Last blog : phpHaze 1.59.1 in Development
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« Reply #5 on: May 04, 2007, 10:36:35 PM »

why using the blob data as image? this will generate a big server load if the site becomes busy...

i was going to warn of something similair.. being that blob can be a *LOT* of data, creating a huge image.. but i tried to give the solution he was seeking Wink
Thank you both for your replies.  I had looked at the blob method, and was mainly experimenting with it more than anything to see how it worked.  In some of my reading I found out that storing as blobs would not be as efficient...and other methods would work better.  I did find that I had to change it to mediumblob to store a file of decent size so I thought it could cause some strain on the server.  The best case scenario will be to just use a file uploader, and store images in a directory to pull them from.  Then you could run something to get them randomly from that folder. 

I found one that will allow photo resizing (big time saver) to exact image height and width, or to maintain the exact image aspect ratio.  http://www.verot.net/ Visit through proxy if anyone wants to check it out. 
Thanks again for the advise and help...Brad
« Last Edit: May 04, 2007, 10:39:16 PM by ?forU »
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6440
39464 credits
Members referred : 374


It's time to use PHP5!


« Reply #6 on: May 04, 2007, 11:10:57 PM »

if you like check this script too:

http://www.finalwebsites.com/snippets.php?id=7 Visit through proxy


Last blog : Just a better Internet portal provided by Google
My Name is Enigo Montoya
*
Posts: 33
188 credits
Members referred : 0


« Reply #7 on: May 05, 2007, 01:36:24 AM »

if you like check this script too:

http://www.finalwebsites.com/snippets.php?id=7 Visit through proxy

Thank you Olaf.  I will check that out!  It looks to be a very popular script.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=6504
Tags : display BLOB info BLOB in database Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: problems with displaying BLOB info from a database
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Nov 22, 2008, 03:53:24 PM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 37.736
Total Topics: 7.650
Total Members: 4.397
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: Janai

34 Guests, 3 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.