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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.