$valid_formats = array("jpg", "png", "gif", "zip", "bmp"); $max_file_size = 999999*999999; //100 kb $path = "../images/"; // Upload directory $count = 0; $aid = all_filter($_GET['aid']); if(isset($_POST['upload_button']) and $_SERVER['REQUEST_METHOD'] == "POST"){ foreach ($_FILES['files']['name'] as $f => $name) { $files = $_POST['files'.$name]; if ($_FILES['files']['error'][$f] == 4) { continue; } if ($_FILES['files']['error'][$f] == 0) { if ($_FILES['files']['size'][$f] > $max_file_size) { $message[] = "$name is too large!."; continue; } elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){ $message[] = "$name is not a valid format"; continue; } else{ if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name)) { $con->query("insert into gallery (`aid`,`files`) values ('$aid','$files')") or die(mysqli_errno()); $count++; header("location: view-gallery.php?aid=".$_GET['aid']."&& albumtitle=".$_GET['albumtitle']."&&albumdesc=".$_GET['albumdesc']." &&albumdate=".$_GET['albumdate']." "); } } } } } <h3>You can upload multiple image in single upload only.</h3> <?php # error messages if (isset($message)) { foreach ($message as $msg) { printf("<p class='status'>%s</p></ br>\n", $msg); } } # success message if($count !=0){ printf("<p class='status'>%d files added successfully!</p>\n", $count); } ?> <?php if(isset($_REQUEST['click'])):?> <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="files[]" multiple="multiple" accept="image/*"> <input type="submit" value="Upload" name="upload_button" class="btn btn-danger"> </form> <?php endif?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)