katsu Posted March 24, 2010 Share Posted March 24, 2010 Hi I'm doing a web application that stores pictures in a database, I don't have a idea how to echo it in a dynamically generated table from the database. I tried several ways: 1.- Using an external php that loads the image, something like this : <?php define("DBSERVER", "server"); define("DBUSER", "user"); define("DBPASS", "pass"); define("DBNAME", "db"); $database= new mysqli(DBSERVER,DBUSER, DBPASS,DBNAME); $query = $database->query("select * from pictures where id = 1"); $data = $query->fetch_assoc(); header('Content-Type: image/jpeg'); echo $data['pic1']; Then, in the table, I put <img src="image1.php" /> and it works on opera, but it doesn't on firefox or internet explorer 2.- Loading it with ajax dynamically, image didn't show up 3.- like the first option, but it echos the img tag with the image from the db like this : <?php define("DBSERVER", "server"); define("DBUSER", "user"); define("DBPASS", "pass"); define("DBNAME", "db"); $database= new mysqli(DBSERVER,DBUSER, DBPASS,DBNAME); $query = $database->query("select * from pictures where id = 1"); $data = $query->fetch_assoc(); echo $data['pic1']; I know I can echo an image adding the header('Content-Type: image/jpeg'); in the php code I've done it before, but I want it to show them inside a content table. I appreciate any help Regards, Link to comment https://forums.phpfreaks.com/topic/196428-displaying-images-from-database/ Share on other sites More sharing options...
litebearer Posted March 24, 2010 Share Posted March 24, 2010 I prefer storing the images in a folder and simply putting the path/name in the db; however... echo "<IMG SRC='" . $var_containing_pic_name . "'>"; Link to comment https://forums.phpfreaks.com/topic/196428-displaying-images-from-database/#findComment-1031350 Share on other sites More sharing options...
katsu Posted March 24, 2010 Author Share Posted March 24, 2010 Yes I think I'll do it that way, it's kind of confusing that <img src"image1.php" /> works for opera, but doesn't for other browsers though... Link to comment https://forums.phpfreaks.com/topic/196428-displaying-images-from-database/#findComment-1031357 Share on other sites More sharing options...
Gighalen Posted March 25, 2010 Share Posted March 25, 2010 How is the data being stored? I'm assuming you're using base64 or some other file->string conversion process? It could have to do with how the data is converted back into an image. Link to comment https://forums.phpfreaks.com/topic/196428-displaying-images-from-database/#findComment-1031414 Share on other sites More sharing options...
litebearer Posted March 25, 2010 Share Posted March 25, 2010 when trying your code in other browsers view the source and see what is there Link to comment https://forums.phpfreaks.com/topic/196428-displaying-images-from-database/#findComment-1031416 Share on other sites More sharing options...
AdRock Posted March 25, 2010 Share Posted March 25, 2010 I prefer storing the images in a folder and simply putting the path/name in the db; however... echo "<IMG SRC='" . $var_containing_pic_name . "'>"; That is exactly how I do it. I just put the filename in the database and echo the filename inside the path to the file. Thtat way you don't have to worry about the path becuase that could change Link to comment https://forums.phpfreaks.com/topic/196428-displaying-images-from-database/#findComment-1031532 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.