adam291086 Posted October 10, 2007 Share Posted October 10, 2007 I have some script for a photogallery. Once the upload script runs it display the message Upload Sucessful. But it displays this message for every single photo. Is there away to limit the amount of times a message is displayed? Quote Link to comment https://forums.phpfreaks.com/topic/72623-question/ Share on other sites More sharing options...
mkosmosports Posted October 10, 2007 Share Posted October 10, 2007 Im sure there is. Can you show us the code? Quote Link to comment https://forums.phpfreaks.com/topic/72623-question/#findComment-366161 Share on other sites More sharing options...
pocobueno1388 Posted October 10, 2007 Share Posted October 10, 2007 You probably have that message in a loop. Take it out. We would have to see your code to help you more. Quote Link to comment https://forums.phpfreaks.com/topic/72623-question/#findComment-366162 Share on other sites More sharing options...
adam291086 Posted October 10, 2007 Author Share Posted October 10, 2007 here is the code. Sorry its so long and not edited, just i am doing it from work with no editor. <html> <head> <?php echo '<META http-equiv=REFRESH content="3;URL=http://www.adamplowman.co.uk/">'; ?> </head> <body> <?php include("GallerySizer.php"); include("config.php"); DEFINE("IMAGE_FULL", '../adam/photos/'); //database connect $db_server ="this works"; $db_user = "this works"; $db_pass = "this works"; $db_name = "this works"; $con = mysql_connect("$db_server","$db_user","$db_pass"); // Album cover $cover = $_FILES['image']['name'][$_POST['album_cover']]; if (!$_REQUEST['process']){ echo("Error! No images chosen for processing. <br />"); echo("Click <a href='index.html'>here</a> to start processing your images."); die(); } elseif (!$_POST['album_id']){ echo("No album selected. Please <a href=\"\">choose an album</a> to upload images to."); die(); } else { for($i = 0; $i < count($_FILES['image']['tmp_name']); $i++){ $fileName = $_FILES['image']['name'][$i]; copy($_FILES['image']['tmp_name'][$i], IMAGE_FULL . $fileName); $thumb = new GallerySizer(); if($thumb->getLocation($_FILES['image']['name'][$i])){ if($thumb->loadImage()){ if($thumb->getSize()){ if($thumb->setThumbnail()){ if($thumb->copyThumbImage()){ if($thumb->resizeImage()){ $thumb->copyResizedImage(); } } } } } else { echo("Invalid image/file has been uploaded. Please upload a supported file-type (JPEG/PNG)"); unlink(IMAGE_FULL . $fileName); die(); } //insert image insert_location($thumb); } } } function insert_location($thumb_obj) { $image_location = $thumb_obj->getImageLocation(); $thumb_location = $thumb_obj->getThumbLocation(); // If image matches cover selection, update album cover if($cover == $_FILES['image']['name'][$i]){ $sql = "UPDATE albums SET album_cover = '" . $thumb_location . "' WHERE album_id = " . $_POST['album_id']; $result = @mysql_query($sql) or die("Error inserting records: " . mysql_error()); } mysql_select_db("db218351273", $con); $sql = ("INSERT INTO photos (photo_id, photo_title, photo_desc, photo_date, photo_location, thumbnail_location,album_id) VALUES('0', '$_POST[photo_title]', '$_POST[photo_desc]', 'NOW()', '$image_location', '$thumb_location', '$_POST[album_id]')"); $result = mysql_query($sql) or die("Error inserting record(s) into the database: " . mysql_error()); if ($result){ $msg .= " Upload OK. The page will now Refresh!<br />"; displayPage($msg, "Upload OK!"); } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/72623-question/#findComment-366164 Share on other sites More sharing options...
pocobueno1388 Posted October 10, 2007 Share Posted October 10, 2007 I'm thinking it's because this line is in the for loop: insert_location($thumb); That is the function that generates the success message. Maybe you could do something like this. First take out the success message from the function, then change the for loop chunk of code to this: <?php for ($i = 0; $i < count($_FILES['image']['tmp_name']); $i++) { $fileName = $_FILES['image']['name'][$i]; copy($_FILES['image']['tmp_name'][$i], IMAGE_FULL . $fileName); $thumb = new GallerySizer(); if ($thumb->getLocation($_FILES['image']['name'][$i])) { if ($thumb->loadImage()) { if ($thumb->getSize()) { if ($thumb->setThumbnail()) { if ($thumb->copyThumbImage()) { if ($thumb->resizeImage()) { $thumb->copyResizedImage(); } } } } } else { echo("Invalid image/file has been uploaded. Please upload a supported file-type (JPEG/PNG)"); unlink(IMAGE_FULL . $fileName); die(); } //insert image if (insert_location($thumb)) { $success = TRUE; } } } if (isset($success)){ $msg .= " Upload OK. The page will now Refresh!<br />"; displayPage($msg, "Upload OK!"); } ?> I'm not positive that will work, but you can give it it a try. Quote Link to comment https://forums.phpfreaks.com/topic/72623-question/#findComment-366180 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.