MySQL Forums
Forum List  »  PHP

Retrieve image from BLOB runs script twice??
Posted by: John Moxon
Date: September 05, 2006 05:27PM

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.




Edited 1 time(s). Last edit at 09/06/2006 07:11AM by John Moxon.

Options: ReplyQuote


Subject
Written By
Posted
Retrieve image from BLOB runs script twice??
September 05, 2006 05:27PM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.