PHP upload multiple files

In this example, we will show a script in PHP to upload multiple files at once. This PHP upload multiple files script works in any standard PHP based server.  First of all, the HTML page will prompt you to select multiple files. Then, as you click Upload, the server will process the files one by one.

First of all, make sure the directive file_uploads is enabled in your php.ini file. This line must be set as follows:

Basically, the only variable you must change is $path, right at the beginning of this PHP script. The PHP upload multiple files script is almost ready to use. Note that you have to create the upload folder. Thus, if your server is Linux based, you may need to set write permissions on it. These permissions can be configured by FTP Online, or else, using your FTP client.

Basic PHP multiple files upload script

This first example is a basic script. Here’s the example. We have created a script named upload.php with this content:

Explanation

For instance, in our example we have placed these files:

/home/mysample/public_html/upload/upload.php – The PHP multiple files upload script
/home/mysample/public_html/upload/files/  – The folder that will receive the uploaded files

Advanced PHP multiple files upload script example

In this second example, one advanced PHP with some features. First, this advanced PHP example will include some file verifications.

This way, if the file already exists in the server, it will show an error. Second, it will check for the filesize. If it exceeds 500kb, will show an error. Then, it includes a file extension verification. This way you can enable only specific file extensions to upload.

 

Conclusion

PHP is perfectly compatible with file uploads. Either single or multiple file uploads. There are some PHP upload multiple files scripts. Other verifications can be added to these files. For instance, file sizes allowed extensions, etc.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *