![]() |
|
#1
|
|||
|
|||
Images in MySQL and PHPhi,
This is prob really easy but im trying to store a image in mysql in a blob. Not aure how to put the image in there to start with and then i want to display the image using php on a webpage including other information from the database. I can get it to show all the text information but no image. Any help would be greatly appriciated |
|||
|
#2
|
||||
|
||||
Re: Images in MySQL and PHPThere is nifty example of doing what you seek here. (follow the $data variable where they do the insert from the upload -- and note the size limitation section near the bottom)
Depending on the scope of what you're trying to do, at our shop, we've avoided using blobs in some instances, and simply store a path-with-filename string (as a varchar) instead. [this could be further simplified to a constant path, and only storing a file name] It seemed sort of wasteful, for some of our uses, to keep images stored on the harddrive and also have the additional storage overhead for 'blobs' in the database. But again, this would all depend on the overall goal/scope of your project. __________________
Use the force...read the source!! WYCIWYG -- what you code is what you get! |
|
#3
|
||||
|
||||
Re: Images in MySQL and PHPI prepared this response earlier and would have posted it sooner if not for some problems with my activation email. So, for what it's worth...
The short answer: To store the image: use file_get_contents() and treat the image data as a string. Use mysql_query() to insert the data into your database. The field your image data is stored in should be of type TINYBLOB, BLOB, MEDIUMBLOB, or LONGBLOB, depending on the size of images you want to store. To retrieve the image: query the database then convert the image data into a usable image using imagecreatefromstring(). Output the image using header() and imagejpeg(). To embed the image in a page along with other HTML elements: use the img tag and point it to a script that retrieves and outputs the image. For example: HTML Code:
The long answer: See this example: misterchucker.com/image_blob_test Other considerations: I get an error 2006 "MySQL server has gone away" when I attempt to store images larger than 1MB. For more on this, see dev.mysql.com/doc/refman/5.0/en/gone-away.html. An alternative to messing with the server configuration is to resize the uploaded image using imageresize() before you send it to the database. Another option would be to store your image files on the filesystem and store just their paths in the database. |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! | IncognitoNet | Web Hosting Advertisements & Offers | 0 | 30-Jan-2005 21:46 |
| RESELLER WEB HOSTING - $9.99/MONTH For 4GB HD & 30GB BW! CPanel, PHP, MySQL & MORE! | IncognitoNet | Web Hosting Advertisements & Offers | 0 | 11-Nov-2004 19:51 |
| PHP, MySQL, WML | skyloon | MySQL / PHP Forum | 0 | 05-Mar-2004 07:53 |
| Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More | EyotaHosts | Web Hosting Advertisements & Offers | 0 | 28-Jun-2003 13:54 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The