johnseito Posted February 22, 2008 Share Posted February 22, 2008 anyone know how I can fix this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/92393-last-pix-upload-doubles-when-i-refresh/ Share on other sites More sharing options...
aeafisme23 Posted February 22, 2008 Share Posted February 22, 2008 some code would be very helpful if you could provide some Quote Link to comment https://forums.phpfreaks.com/topic/92393-last-pix-upload-doubles-when-i-refresh/#findComment-473373 Share on other sites More sharing options...
johnseito Posted February 22, 2008 Author Share Posted February 22, 2008 here is the code, it seems that the variable $filename is always there and is always the same name of the last uploaded picture. so when you refresh the page this variable name gets inserted into the sql, again and again and again when you keep refreshing it. but when you upload a new picture, this variable will have a new name, and then when you refresh this name will be inserted into the database again and again, therefore repeating the pictures (doubling it). so in essence when you refresh you are running the code to insert the variable name to the sql. we need to change this from happening, if you have any suggestion let me know. <?php $dir = "pictures/"; $target = $dir . basename( $_FILES['uploaded']['name']) ; //$ok=1; $fileName = $_FILES['uploaded']['name']; //connects to database mysql_connect("localhost", "TEST1", "TEST") or die (mysql_error()); mysql_select_db("test") or die (mysql_error()); mysql_query("insert into picture(photo) values('$fileName')"); $allowed_type = array('image/jpg','image/tif','image/gif','image/pjpeg','image/png','image/jpeg'); if(in_array($uploaded_type,$allowed_type)){ if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "<font color =red> The file </font><b>". basename( $_FILES['uploaded']['name']). "</b> <font color=red>has been uploaded to the</font>". "<b> $dir </b></font>"."<font color=red> directory.</font><br><br>"; $data = mysql_query("SELECT * FROM picture") or die(mysql_error()); while($info = mysql_fetch_array( $data ))//Puts it into an array { Echo "<img src=$dir".$info[photo]." width=200 height=200> <br>"; } }else { echo "<font color=red> Sorry, there was a problem uploading your file. Please try again!</font><br><br>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/92393-last-pix-upload-doubles-when-i-refresh/#findComment-474016 Share on other sites More sharing options...
BlueSkyIS Posted February 22, 2008 Share Posted February 22, 2008 i would prevent a refresh of the same page, using POST to the page, then header() to go somewhere else after the upload is completed. Quote Link to comment https://forums.phpfreaks.com/topic/92393-last-pix-upload-doubles-when-i-refresh/#findComment-474057 Share on other sites More sharing options...
johnseito Posted February 22, 2008 Author Share Posted February 22, 2008 I did use POST. <form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: <input type="file" name="uploaded" /><br /> <input type="submit" name="submit" value="Upload" /> </form> could you provide an example? thanks - Quote Link to comment https://forums.phpfreaks.com/topic/92393-last-pix-upload-doubles-when-i-refresh/#findComment-474113 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.