PHPackages                             phpuploader/phpfileuploader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. phpuploader/phpfileuploader

ActiveLibrary[File &amp; Storage](/categories/file-storage)

phpuploader/phpfileuploader
===========================

Class to facilitate the process of uploading files using PHP.

v1.0.0(3y ago)327MITPHP

Since Feb 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/91ahmed/PHPFileUploader)[ Packagist](https://packagist.org/packages/phpuploader/phpfileuploader)[ RSS](/packages/phpuploader-phpfileuploader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHPFileUploader
---------------

[](#phpfileuploader)

Class to facilitate the process of uploading files using PHP.

### Features

[](#features)

- Upload single or multiple file.
- Generate random name for the files.
- Create a custom name for the files.
- Files verification.

### Installation

[](#installation)

via composer

```
composer require phpuploader/phpfileuploader
```

### Simple Example

[](#simple-example)

```
require ('vendor/autoload.php');

$file = new \PhpFileUploader\Uploader('inputfilename'); // Specify the input file name.
$file->path('/files/'); // Specify the files destination path.
$file->upload(); // move uploaded files (You should call this method at the end).
```

### Generate random name

[](#generate-random-name)

You can use this method `createRandomName()` to generate a random name for the files. If you don't call this method the files will be uploaded with their original name.

**Example:**

```
$file = new \PhpFileUploader\Uploader('inputfilename');
$file->path('/files/');
$file->createRandomName(); // Generates random name.
$file->upload();
```

### Create custom name

[](#create-custom-name)

You can use this method `createFileName()` to create a custom name for the file.

**Example:**

```
$file = new \PhpFileUploader\Uploader('inputfilename');
$file->path('/files/');
$file->createFileName('myCustomName'); // Create custom name.
$file->upload();
```

### Check errors

[](#check-errors)

This method `displayUploadErrors()` will return an array with error messages. The library will verify the files to check whether the file exists, selected or has been uploaded successfully or not.

### Upload multiple file

[](#upload-multiple-file)

- Add this attribute `multiple="multiple"` to the **HTML** input to allow you select multiple file.
- Make the input name as array `name="files[]"`. The class will process all the selected files and upload them to the server.

### Full Example with HTML form

[](#full-example-with-html-form)

```
require ('vendor/autoload.php');

if (isset($_POST['upload']))
{
    $file = new \PhpFileUploader\Uploader('myFile'); // Specify the input file name.
    $file->path('/files/'); // Specify the files destination path.
    $file->createRandomName(); // Generate random name.
    $file->upload(); // move uploaded files (You should call this method at the end).

    // Display errors as array
    $file->displayUploadErrors()

    // Check if the files uploaded or not
    if ($file->success()) {
	    // Success
		echo 'Files have been uploaded';
	} else {
		// Failed
	}
}
```

```
