PWD Posted April 24, 2006 Share Posted April 24, 2006 I've written the following multiple file upload script which works flawlessly:[code]if(!empty($_POST['go'])) { foreach($_FILES['fileup']['error'] as $key => $error) { if($error == UPLOAD_ERR_OK) { $filename = $_FILES['fileup']['name'][$key]; $filetmp = $_FILES['fileup']['tmp_name'][$key]; $filetype = $_FILES['fileup']['type'][$key]; $filesize = $_FILES['fileup']['size'][$key]; $filedest = 'uploads/'; if($filetype == 'image/jpeg') { move_uploaded_file($filetmp, $filedest . $filename); } }}include 'success.php';}else { echo print_r($_FILES);} [/code][b]My Problem:[/b] My 'success.php' page is suppose to list a confirmation for each image uploaded, yet as it stands, it will ONLY display the last image's information. Yet all 3 images upload fine. I assume I'll have to put all the information into an array?!?Here is 'success.php':[code]<p> Here is a recap of the photos you uploaded:</p><ul class="none"> <li>Image Name: <?php echo $filename; ?></li> <li>Image Type: <?php echo $filetype; ?></li> <li>Image Size: <?php echo $filesize; ?> bytes</li></ul>[/code]My gratitude ahead of time for helping me learn... Quote Link to comment https://forums.phpfreaks.com/topic/8313-trouble-understanding-arrays/ Share on other sites More sharing options...
kenrbnsn Posted April 24, 2006 Share Posted April 24, 2006 You have the include outside the foreach loop. If you had lined up the brackets better, that would have been made very clear. Good indentation is your friend.Ken Quote Link to comment https://forums.phpfreaks.com/topic/8313-trouble-understanding-arrays/#findComment-30314 Share on other sites More sharing options...
sanfly Posted April 24, 2006 Share Posted April 24, 2006 There are two ways i can think of, one is to put the information into an array as you go, second is to include it in the loopPlease note i havent tested these properly, so there may be syntax errors, but it should give you an idea[code]if(!empty($_POST['go'])) {foreach($_FILES['fileup']['error'] as $key => $error) { if($error == UPLOAD_ERR_OK) { $filename = $_FILES['fileup']['name'][$key]; $filetmp = $_FILES['fileup']['tmp_name'][$key]; $filetype = $_FILES['fileup']['type'][$key]; $filesize = $_FILES['fileup']['size'][$key]; $filedest = 'uploads/'; if($filetype == 'image/jpeg') { move_uploaded_file($filetmp, $filedest . $filename); $theFile[] = $filename; $theType[] = $filetype; $theSize[] = $filesize; }}}include 'success.php';}else { echo print_r($_FILES);} // Success.php<p> Here is a recap of the photos you uploaded:</p><? $num = count($theFile);for($i = 0; $i < $num; $i++){ ?><ul class="none"> <li>Image Name: <?php echo $theFile[$i]; ?></li> <li>Image Type: <?php echo $theType[$i]; ?></li> <li>Image Size: <?php echo $theSize[$i]; ?> bytes</li></ul><? } ?>[/code][code]if(!empty($_POST['go'])) {echo "<p>Here is a recap of the photos you uploaded:</p>";foreach($_FILES['fileup']['error'] as $key => $error) { if($error == UPLOAD_ERR_OK) { $filename = $_FILES['fileup']['name'][$key]; $filetmp = $_FILES['fileup']['tmp_name'][$key]; $filetype = $_FILES['fileup']['type'][$key]; $filesize = $_FILES['fileup']['size'][$key]; $filedest = 'uploads/'; if($filetype == 'image/jpeg') { move_uploaded_file($filetmp, $filedest . $filename); <ul class="none"> <li>Image Name: <?php echo $filename; ?></li> <li>Image Type: <?php echo $filetype; ?></li> <li>Image Size: <?php echo $filesize; ?> bytes</li></ul><br><br> } } }include 'success.php';}else { echo print_r($_FILES);} [/code] Quote Link to comment https://forums.phpfreaks.com/topic/8313-trouble-understanding-arrays/#findComment-30317 Share on other sites More sharing options...
PWD Posted April 24, 2006 Author Share Posted April 24, 2006 [b]KENRBNSN:[/b] When I put the include() into the foreach() loop, it gives me 3 pages; one right on top of another...[b]SANFLY: [/b] Exactly the brain storm I was looking for....Always grateful to the both of you.... Quote Link to comment https://forums.phpfreaks.com/topic/8313-trouble-understanding-arrays/#findComment-30322 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.