What's WP
Find Everything Related to WordPress - Best Tutoriasl on WordPress!
How to Use PHP to Upload Multiple Files?

How to Use PHP to Upload Multiple Files?

Running a website may encounter various problems frequently and how to use PHP to upload multiple files is a basic and common-asked one. PHP is a programming language that can send orders to servers and accordingly you can use it to upload any files no matter they are images, sounds, or writing files.

Almost every hosting package supports PHP scripts such as plans in BlueHost, HostGator and A2Hosting. However, for people who know nothing about codes and HTLM, uploading files with PHP is difficult. In the following, we are going to explain how to use PHP to upload multiple files step by step.

Upload Multiple Files with PHP Manually

You may wonder that WordPress is so powerful that it provides all kinds of plugins to meet various demands from users. For example, you want to add music to your site, then there are music player plugins for you; you intend to create a sitemap for your site, then, there are sitemap plugins for you.

advantagesOf course, there are file uploading plugins for you. However, uploading files with PHP has its special advantages. It is more convenient because you just need to write several lines of codes. Besides, plugins can take a lot of sever resources which may make your page loading speed slower. Under this condition, we are going to tell you how to upload multiple files with PHP in detail

Creating an Upload Form

If there is a form for users to upload files, then, the whole process can be very easy and convenient. Thus, for long term plan, you need to create a form at first. Just copy the code in below and you can achieve this.

Create Upload Form

Note that the attribute type=”file” is to render a file upload control in web browser.

When user chooses to submit, the data will be sent to the server and users will be leaded to uploader.php.

Creating the Upload Scripts

Now, you have a file upload form, the next step is to build the upload script to upload file from local computer to the server. Here is the code and save it in uploader.php.

create upload scripts

$_FILES[“file”][“name”] means the upload file name.
$_FILES[“file”][“type”] presents file type you are going to upload.
$_FILES[“file”][“size”] stands for the size of the file.

Saving File

As soon as the uploader.php is implemented, your uploaded files will be kept on the server temporarily. However, if the script is over, the temporary uploaded file will disappear. Thus, you need to move them to somewhere else to ensure it can be saved as long as you want. To achieve this, you need to know two things, the first it to know whether the file is successfully uploaded and the second is to find out where to place it. The second step can be handled by yourself; therefore, in the following, we just give you the code to exam if the file is uploaded.

save file


Lucy has been a very experienced SEOer, technical writer, web developer, c# developer since 2002. Now she owns a startup in San Francisco, CA, focusing on running a couple of blogs to share knowledge and experience with global readers and deliver exceptional results to global sponsors by leveraging the power of Internet.