Jump to content

Images from database, <img not working...?


d22552000

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/97170-images-from-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.