Jump to content

Retrieving image from mysql BLOB runs script twice??


johnmoxon_uk

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]
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.