Multiples upload files
Publié le 13 juillet 2015 | Par adminblog | Commenter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
<?php $numoffiles = 5; echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">' ; for ($i = 1; $i<=$numoffiles; $i++) { echo 'Image'.$i.': <input type="file" name="file[]" size="30" style="cursor:hand;"/> <br /> '; } echo '<input type="submit" name="action" value="Upload" />'; echo '</form>'; if(isset($_POST['action'])) { $uploaddir = 'C:/PHP/uploadtemp/'; for ($i =0; $i<$numoffiles; $i++) { $filename = $_FILES['file']['name'][$i]; $filetmp = $_FILES['file']['tmp_name'][$i]; $filesize = $_FILES['file']['size'][$i]; $filetype = $_FILES['file']['type'][$i]; $ext = substr(strrchr($filename, "."),1); $conf = $uploaddir . $filename; $filepath = $uploaddir . $filename; if ($filename != "") { if (!file_exists($filepath)) { if ($ext == "jpg" || $ext == "gif" || $ext == "tiff" || $ext == "png" || $ext == "bmp") { if($filesize < "500000") { $upload = move_uploaded_file($filetmp, $filepath); echo '<font color=blue>'. $filename . ' <i>was successfully uploaded...</font><br />'; } else { echo '<font color=red>'.$filename . ' <i>greater than the maximum file size allowed...</font><br />'; } } else { echo '<font color=red>'. $filename . ' <i>is invalid file type...</font><br />'; } } else { echo $filename . ' <i>already exists...</i><br />'; } } } } ?> |
Commentaires récents