Uploading multiple files simultaneously is not very different from uploading a single file. All you need to do is use a different name for each file that you want to use: <form enctype="multipart/form-data" action="do_upload.php" <input name="Afile[]" type="file" size="80"> When the above form is submitted, the arrays $_FILES['Afile'], $_FILES['A']['name'], and $_FILES['Afile']['size'] will be initialized and all of them will be numerically indexed. For example say you submit three files with the names uploader.html, fileprocess.php and what.php. The $_FILES['Afile']['name'][0] array will contain uploader.html and the $_FILES['Afile']['name'][1] array will contain what.php, and so on. All of the file attributes such as size and name will be available for each file that you submitted. Once you've submitted the form you simply do a "for each" loop and display the form information. Another way in which you can upload multiple files is by explicitly giving the "name" part of the form input a different name: <form enctype="multipart/form-data" action="do_upload.php" <input name="Afile1" type="file" size="80"> And then process them as normal. Create another HTML document and call it uploaderfrm.html. Add the following code: Uploader.html <html> Now, let's create the script that will handle form data. Create a new PHP Document and save it as uploader_do.php. Script:uploader_do.php <?php $uploaddir="c:uploads"; As with our previous upload script, first we define where we want to store the uploaded files by declaring '$uploaddir="c:uploads";' From this declaration we can see that our files are going to be stored on our C drive. Next we check whether there are any errors in the submitted File array: 'if(isset($_FILES['AFile']['error'])){ ' If there are any errors, the files will not be uploaded. If on the other hand there are no errors, the files are uploaded by the 'move_upload_file()' function. There's another way that you can dynamically create input fields on a form to upload files. If you present a user with a form asking how many files he or she wants to upload, once you have the number you can simply create a dynamic form with n number of input tags and continue from there.
blog comments powered by Disqus |
|
|
|
|
|
|
|