| | |
displaying uploaded image
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2008
Posts: 74
Reputation:
Solved Threads: 5
you are doing fine. Don't store the actual image in your database. To display you can do something like this:
php Syntax (Toggle Plain Text)
<?php // just so we know it is broken error_reporting(E_ALL); // some basic sanity checks if(isset($_GET['image_id']) && is_numeric($_GET['image_id'])) { //connect to the db $link = mysql_connect("localhost", "username", "password") or die("Could not connect: " . mysql_error()); // select our database mysql_select_db("database_name") or die(mysql_error()); // get the image from the db $sql = "SELECT image FROM TABLE WHERE image_id=0"; // the result of the query $result = mysql_query("$sql") or die("Invalid query: " . mysql_error()); // set the header for the image header("Content-type: image/jpeg"); echo mysql_result($result, 0); // close the db link mysql_close($link); } else { echo 'Please use a real id number'; } ?>
•
•
Join Date: Jul 2006
Posts: 4
Reputation:
Solved Threads: 1
Only think I will point out,
Is that the uploaded image when stored would have to be converted to jpeg for that to exclusively work. When working with files you have the option of giving the uploaded images specific filenames and then rendering them through the use of functions such as imagecreatefromjpeg and imagejpeg. What you might want to do instead of using files and expanding on the database idea, would be to store the mime-type, rather then returning each image as an apparent jpeg.
Is that the uploaded image when stored would have to be converted to jpeg for that to exclusively work. When working with files you have the option of giving the uploaded images specific filenames and then rendering them through the use of functions such as imagecreatefromjpeg and imagejpeg. What you might want to do instead of using files and expanding on the database idea, would be to store the mime-type, rather then returning each image as an apparent jpeg.
![]() |
Similar Threads
- Generate Thumbnail images on the fly. (PHP)
- displaying image from database (PHP)
- displaying images (PHP)
- displaying images (MySQL)
- Displaying images from mysql database (PHP)
- displaying image from db (ASP.NET)
- CSS Border's Shadow ??? (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: Should I echo out password value in the password field?
- Next Thread: for loop inside if statement
Views: 707 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery js limit link login loop mail mediawiki menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql stored structure subdomain syntax system table tutorial update updates upload url validation validator variable video web xml youtube





