| |||||||||||
| |||||||||||
Display an image from a MySQL database in a web page via PHP
There's lots of clever scripts around to tell you how to get images in and out of databases, but nothing simple to show you the principles of including such an image via (say) PHP in a web page. So here goes.
you need TWO URLs - you need the HTML page that's going to contain the image, AND you need a second URL - PHP in my example - that's going to retrieve the image and feed it out as part of the page. You CANNOT feed out both the HTML and the image from the same http request. Here's a sample HTML page we're going to include an image in: <html>Then you need the PHP script - called picscript.php in the same directory in my example: <?phpIf you want to try it out, then the HTML page is here. Want to take this further? As a next step, I would validate the connection after the mysql_connect, and check that an image really had been returned by the mysql_query ... substituting a default image if not. We host a complete working example of image upload, save to database, select from database and display all via a PHP script. See article on the subject There's a forum discussion here. (written 2006-11-22 16:48:22) Associated topics are indexed under H113 - Using MySQL Databases in PHP PagesH999 - Additional PHP Material S154 - MySQL - Designing an SQL Database System H113 - Using MySQL Databases in PHP Pages H309 - PHP - Maps, Graphics and Geographics
Some other Articles
SnaggingWinter at Well House Manor - Open Houses Swipe cards for hotel rooms - Security issues Bratton and Edington new town, Wiltshire Display an image from a MySQL database in a web page via PHP Global, Superglobal, Session variables - scope and persistance in PHP Autumn leaves in Wiltshire - Potterne Clustering, load balancing, mod_rewrite and mod_proxy Course Joining package - updated A tale of a wee wall 1638 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||