d22552000 Posted March 20, 2008 Share Posted March 20, 2008 Well, I have uploaded and stored images in a database, and they store fine. I also have them shown on the page, which does not work with the <img tag, in FF it just shows the alt="" text, and in IE it shows a small X (picture not found error). When I go to the EXACT url outputted by the page, I see the image fine, in both internet explorer and in fire fox. Here is my code for uploading the images: WORKING $tmpName = $_FILES['file']['tmp_name']; $fileName = addslashes($_FILES['file']['name']); $fileSize = addslashes($_FILES['file']['size']); $fileType = addslashes($_FILES['file']['type']); $message = trim(addslashes($_POST['msg'])); $subject = trim(addslashes($_POST['sub'])); $theSize = getimagesize($tmpName); $ip = $_SERVER['REMOTE_ADDR']; if (empty($message) || empty($subject)) { $status = "Fields were left empty!"; } $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); $res = mysql_query("INSERT INTO `image` ( `ID` , `MSG` , `DATA` , `SIZE` , `TYPE` , `NAME` , `IPADDR` , `SUBJECT` , `IMGSIZE` ) VALUES ( NULL , '$message' , '$content' , '$fileSize' , '$fileType' , '$fileName' , '" . $ip . "' , '$subject' , '" . addslashes($theSize[3]) . "' );") or die(mysql_error()); Here is the code for showing the images: WORKING $res = mysql_query("SELECT * FROM `image` WHERE `ID` = '" . $_GET['img'] . "';"); while ($row = mysql_fetch_assoc($res)) { header("Content-length: " . $row['SIZE']); header("Content-type: " . $row['TYPE']); print $row['DATA']; exit(); } Here is the code that makes the image tags and tables: NOT WORKING? $res = mysql_query("SELECT * FROM `image` ORDER BY `ID` DESC LIMIT 30;"); while ($row = mysql_fetch_assoc($res)) { echo " <tr> <th class=\"postblock\"><img alt='" . $row['ID'] . "' scr='index.php?img=" . $row['ID'] . "' " . $row['IMGSIZE'] . "></th> <th class=\"reply\"><big>" . $row['SUBJECT'] . "</big><br />" . $row['MSG'] . "</th> </tr> "; } Can you please tell me why it does not work? This is what it outputs to the browser: <tr> <th class='postblock'><img alt='6' scr='index.php?img=6' width='200' height='200' /></th> <th class='reply'><big>{subject}</big><br />{message}</th> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/97170-images-from-database/ Share on other sites More sharing options...
RottNKorpse Posted March 20, 2008 Share Posted March 20, 2008 sorry to bring this to your attention but you are probably going to want to kick yourself after I point it out. scr='index.php?img= should be src='index.php?img= Quote Link to comment https://forums.phpfreaks.com/topic/97170-images-from-database/#findComment-497232 Share on other sites More sharing options...
d22552000 Posted March 20, 2008 Author Share Posted March 20, 2008 I AM kicking myself right now, trying out the new code... Ya it works... *sigh*... Quote Link to comment https://forums.phpfreaks.com/topic/97170-images-from-database/#findComment-497235 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.