Jump to content

Archived

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

johnmoxon_uk

Retrieving image from mysql BLOB runs script twice??

Recommended Posts

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.

[code]
<?
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();
?>

[/code]

Thanks in advance for your help
Cheers
John

[b][color=red]--

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.[/color][/b]

Share this post


Link to post
Share on other sites
Yeah, FF is crap -- try dropping the disposition header, it's not really necessary unless you're serving an attachment.

Share this post


Link to post
Share on other sites

×

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.