Jump to content


Photo

Retrieving image from mysql BLOB runs script twice??


  • Please log in to reply
1 reply to this topic

#1 johnmoxon_uk

johnmoxon_uk
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 05 September 2006 - 11:39 PM

Hi There

I've written a script to retrieve an image stored in a mysql BLOB, and simultaneously query and update a separate mysql table containing a counter variable. The script successfully updates the counter variable, then retrieves the image.  However the script then appears to run a second time when I print the image to screen causing the counter to be updated twice for every 1 image retrieval?? Any ideas welcomed.

I've included a sample script below to hopefully clarify my problem.

<?
if(isset($_GET['clientID'])){ //clientID refers	to individual client record in the user database
		
	
	require_once('../../data/mysql_connect.inc'); // Connect to the database.
	$i = $_GET['clientID'];
	
	//retrieve counter from user table
	$query = "SELECT counter FROM user_table WHERE user_id = $i"; //build query
	$result = mysql_query($query) or die(mysql_query()); //execute query
	list($counter) = mysql_fetch_array($result);
		
	$addToCounter = $counter + 1; // add one view to counter tally
		
	//build query to update counter in db
	$query = "UPDATE user_table SET counter = $addToCounter WHERE user_id = $i LIMIT 1";
	$result = mysql_query($query); //execute query		
}

##showimage
if(isset($_GET['image'])){

	//retrieve correct image from the downloads db
	require_once('../../data/mysql_connect.inc'); // Connect to the database.
	
	$fileID = $_GET['image']; // set file id for query
	$query = "SELECT file_name, file_size, file_type, content " .
			 "FROM downloads WHERE upload_id = '$fileID'"; //build query
	
	$result = mysql_query($query) or die(mysql_error()); //execute query
	list($name, $size, $type, $content) = mysql_fetch_array($result);
	

	//set content headers for displaying image
	header('Content-Disposition: filename="'.$name.'"');
	header("Content-Type: " . $type);
	header("Content-Length: " .$size);
	
	echo $content; //print or return image

}
mysql_close();
exit();
?>


Thanks in advance for your help
Cheers
John

--

Just found out, this seems to be a problem on Firefox browser only same problem does not occur on IE.  So could be a problem with the way the different browser read 'headers'. Any ideas for a work-around?
Cheers.


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 September 2006 - 01:35 PM

Yeah, FF is crap -- try dropping the disposition header, it's not really necessary unless you're serving an attachment.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users