SyNK Posted December 1, 2009 Share Posted December 1, 2009 Hello all, I know there are tons of posts on this everywhere, but none of the solutions people have given in them are working for me. I'm creating a webpage that stores project information, each project can have multiple pictures showing progress. I've made it so that when you click on a project name all of the information on that project is display. Now I need to figure out how to display the pictures that have been uploaded. This is slightly problematic because not only am I displaying other things besides the pictures on the page, I'm also trying to display multiple pictures. Currently, when I try to display the pictures I'm getting binary junk or the alt tag for my images. Everything else displays correctly. The database we are using is phpMyAdmin 3.2.2... I assume that uses MySql, I'm not sure how to find out the version... The blob is of type mediumblob and has the binary attribute. The comments table has three fields: project, comment, and picture. Here's my code: <?php //connect to DB $pName = $_POST['currProj']; if($pName != "") { $query = sprintf("select * from `projects` where `name` = '$pName'"); $result = mysql_query($query); // display other information $query = sprintf("select * from `comments` where `project` = '$pName'"); $result = mysql_query($query); if(mysql_num_rows($result) >= 1) { for($i = 0; $i < mysql_num_rows($result); $i++){ $row = mysql_fetch_array($result); echo " <br /><br /><label>Picture:</label> "; $img = base64_decode($row['picture']); // header('Content-type: image/jpeg'); // doing this displays binary/ascii mess // echo $img; // echo "<img src=\"getImage.php?count=$i&projName=$pName\" alt=\"error\" />"; // displays 'error' echo " <br /><label>Comment:</label> ".$row['comment']; } } } mysql_close($dbh); ?> Code for getImage.php: <?php // connect to database $num = $_GET['count']; $pName = $_GET['projName']; if($pName != "") { $query = sprintf("select * from `comments` where `project` = '$pName'"); $result = mysql_query($query); if(mysql_num_rows($result) >= 1) { for($i = 0; $i < mysql_num_rows($result); $i++){ if($i == $count){ // only display 1 picture at a time $row = mysql_fetch_array($result); $img = base64_decode($row['picture']); header('Content-type: image/jpeg'); echo $img; } } } } else echo "Unknown project."; mysql_close($dbh); ?> Suggestions on what I could be doing wrong? Also, apologies if this is in the wrong place. Link to comment https://forums.phpfreaks.com/topic/183654-displaying-blob-pictures/ Share on other sites More sharing options...
fenway Posted December 4, 2009 Share Posted December 4, 2009 Yes, it's the wrong place -- and more importantly, you're not describing the upload process Link to comment https://forums.phpfreaks.com/topic/183654-displaying-blob-pictures/#findComment-971234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.