Subscribe to RSS Feed

Can you imagine how troublesome if we have to upload a file or document which is quite a lot to the web server. If we just rely on the application we’ve ever uploaded, must be very tiring and boring. Why is that? Yes, of course, because the application is only able to send one document in a single upload.

Therefore we need to modify the application to be able to send many files in one upload. Sure makes our job easier if we can upload many documents at once with just one click. In addition to more practical, this approach can also save the bandwidth of the Internet.

We can create a web application to upload multiple files in a way to save the information which we will upload the file in an array variable. The technique is relatively easy by adding brackets or [] behind the name tag on a form input that we make.

For example we can see in the sample code below.

action=”upload.php” <form method=”POST” enctype=”multipart/form-data”>
<input <p> name=”userfile[]” type=”file” /> </ p>
<input <p> name=”userfile[]” type=”file” /> </ p>
<p> value=”Upload” /> <input type=”submit” name=”submit”
</ Form>

When we click the Upload button, automatically all the files that we send will be stored in a variable array $ _FILES ['userfile']. Almost the same as the previous application was not it? The difference only lies in the input tag name only.

So now how do I handle data at the server side? Not much different from the previous application. Only, in this case the data that is sent not just one but several pieces of data (in this example there are two) are all stored in the variable $ _FILES ['userfile'].


Surely you remember that the arrays $ _FILES itself actually contains some information related to files or documents that we upload. $ _FILES Array is an array of compounds consisting of:

$ _FILES ['Userfile'] ['name']

This array contains the actual name (the original) of files or documents stored on the user’s computer before the files are uploaded to the server.

$ _FILES ['Userfile'] ['tmp_name']

This array contains the temporary filename of a file or document that is uploaded. The location of this file in a temporary directory on the web server.

$ _FILES ['Userfile'] ['size']

This array contains information about how the size (in bytes) of file or document that is uploaded.

$ _FILES ['Userfile'] ['type']

This array contains the MIME type of uploaded files or documents, eg image / jpeg, image / png, image / gif, text / plain, and so forth.

For cases such as multiple file upload application that we make this, array $ _FILES above we can access using the index number that indicates the order of the files that we upload. For example, if the file that we upload is gambar_2.jpg gambar_1.jpg, and then the information will be stored on the file name in $ _FILES array with the following structure.

$ _FILES ['Userfile'] ['name'] [0] = ‘pic_1.jpg’;
$ _FILES ['Userfile'] ['name'] [1] = ‘pic_2.jpg’;

Furthermore, we can save the file in the same way as in previous applications. Here’s an example.

$ Jumlah_file = count ($ _FILES ['userfile'] ['name']);
$ Path = pathinfo ($ _SERVER ['PHP_SELF']);

for ($ i = 0; $ i <$ jumlah_file; $ i + +)
(
$ Tmp_file = $ _FILES ['userfile'] ['tmp_name'] [$ i];
$ Filetype = $ _FILES ['userfile'] ['type'] [$ i];
$ Filesize = $ _FILES ['userfile'] ['Size'] [$ i];
$ Filename = $ _FILES ['userfile'] ['name'] [$ i];
$ Destination = $ path ['dirname']. ‘/ Data /’. $ Filename;
move_uploaded_file ($ tmp_file, $ _SERVER ['DOCUMENT_ROOT']. $ destination);
)

VN:F [1.9.1_1087]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.1_1087]
Rating: 0 (from 0 votes)
Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Diigo
  • email
  • LinkedIn
  • MisterWong
  • MySpace
  • StumbleUpon
  • Technorati
  • Twitter

Related posts:

  1. Upload Wordpress Step By Step To Server Hosting
  2. Hosting and Domain
  3. Optimize Images For Web Using RIOT
  4. Beautiful Joomla With Web Intro
  5. Import Article From Blog To Facebook

Tags: , , , , , , , ,

Leave a Reply

CommentLuv Enabled
SEO Powered by Platinum SEO from Techblissonline