johnmoxon_uk Posted September 5, 2006 Share Posted September 5, 2006 Hi ThereI'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 }##showimageif(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 helpCheersJohn[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 https://forums.phpfreaks.com/topic/19834-retrieving-image-from-mysql-blob-runs-script-twice/ Share on other sites More sharing options...
fenway Posted September 6, 2006 Share Posted September 6, 2006 Yeah, FF is crap -- try dropping the disposition header, it's not really necessary unless you're serving an attachment. Link to comment https://forums.phpfreaks.com/topic/19834-retrieving-image-from-mysql-blob-runs-script-twice/#findComment-87088 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.