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:
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(100, 30);
// white background and blue text $bg = imagecolorallocate($im, 255, 255, 255); $textcolor = imagecolorallocate($im, 0, 0, 255);
// write the string at the top left imagestring($im, 5, 0, 0, "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 »
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....
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.
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($handle, filesize($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>"; }
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
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
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/ 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:
Posts: 6440
39464 credits Members referred : 374