omar999 Posted September 9, 2013 Share Posted September 9, 2013 (edited) I have a working example below of a single file input upload via php and now I'd like to upload multiple files either by iterating through each input type="file". I've read that the multiple attribute on the input tag is not supported below IE10 so I think the best way would be to have several input type=files in order to loop through them any help is appreciated <input type="file" name="FilesUpload1" class="filesUpload" /> <input type="file" name="FilesUpload2" class="filesUpload" /> <input type="file" name="FilesUpload3" class="filesUpload" /> <?php //Сheck that we have a file if((!empty($_FILES["FilesUpload1"])) && ($_FILES['FilesUpload1']['error'] == 0)) { //Check if the file is JPEG image and it's size is less than 350Kb $filename = basename($_FILES['FilesUpload1']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); //check file extension if ((($ext == "gif") || ($ext == "jpeg") || ($ext == "jpg") || ($ext == "png") || ($ext == "doc") || ($ext == "docx") || ($ext == "rtf") || ($ext == "txt") || ($ext == "pdf")) //check file mime && (($_FILES["FilesUpload1"]["type"] == "image/gif") || ($_FILES["FilesUpload1"]["type"] == "image/jpeg") || ($_FILES["FilesUpload1"]["type"] == "image/jpg") || ($_FILES["FilesUpload1"]["type"] == "image/pjpeg") || ($_FILES["FilesUpload1"]["type"] == "image/x-png") || ($_FILES["FilesUpload1"]["type"] == "image/png") || ($_FILES["FilesUpload1"]["type"] == "application/msword") || ($_FILES["FilesUpload1"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") || ($_FILES["FilesUpload1"]["type"] == "application/rtf") || ($_FILES["FilesUpload1"]["type"] == "text/plain") || ($_FILES["FilesUpload1"]["type"] == "application/pdf")) //check file size is less than 1048576 bytes [1 MB] && (($_FILES["FilesUpload1"]["size"] < 1048576))) { //Determine the path to which we want to save this file $newname = dirname(__FILE__).'/../entries/'.$_POST["CompanyName"].'-'.$filename; //Check if the file with the same name is already exists on the server if (!file_exists($newname)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['FilesUpload1']['tmp_name'],$newname))) { echo "It's done! Your file has been saved."; } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["FilesUpload1"]["name"]." already exists"; } } else { echo "Error: Only .gif, .jpeg, .jpg, .png, .doc, .docx, .rtf, .txt, .pdf files under 1 MB are accepted for upload."; } } else { echo "Error: No file uploaded"; } ?> Edited September 9, 2013 by omar999 Quote Link to comment https://forums.phpfreaks.com/topic/282007-php-multiple-file-upload-using-array-or-for-loop/ Share on other sites More sharing options...
fastsol Posted September 9, 2013 Share Posted September 9, 2013 Here is a good tutorial on the "multiple" attribute and how to iterate through multiple file uploads the correct way. http://www.youtube.com/playlist?list=PL7413DDD1EB6A14BD Quote Link to comment https://forums.phpfreaks.com/topic/282007-php-multiple-file-upload-using-array-or-for-loop/#findComment-1448837 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.