1if (isset($_POST['submit'])) {
2 $j = 0; //Variable for indexing uploaded image
3
4 $target_path = "uploads/"; //Declaring Path for uploaded images
5 for ($i = 0; $i < count($_FILES['file']['name']); $i++) { //loop to get individual element from the array
6
7 $validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed
8 $ext = explode('.', basename($_FILES['file']['name'][$i])); //explode file name from dot(.)
9 $file_extension = end($ext); //store extensions in the variable
10
11 $target_path = $target_path.md5(uniqid()).
12 ".".$ext[count($ext) - 1]; //set the target path with a new name of image
13 $j = $j + 1; //increment the number of uploaded images according to the files in array
14
15 if (($_FILES["file"]["size"][$i] < 100000) //Approx. 100kb files can be uploaded.
16 && in_array($file_extension, $validextensions)) {
17 if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) { //if file moved to uploads folder
18 echo $j.
19 ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
20 } else { //if file was not moved.
21 echo $j.
22 ').<span id="error">please try again!.</span><br/><br/>';
23 }
24 } else { //if file size and file type was incorrect.
25 echo $j.
26 ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
27 }
28 }
29}
30