An open API service indexing awesome lists of open source software.

https://github.com/91ahmed/phpfileuploader

Class to facilitate the process of uploading files using PHP.
https://github.com/91ahmed/phpfileuploader

file-upload php php-file-upload

Last synced: 16 days ago
JSON representation

Class to facilitate the process of uploading files using PHP.

Awesome Lists containing this project

README

        

## PHPFileUploader
Class to facilitate the process of uploading files using PHP.

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

### Installation
via composer
``` bash
composer require phpuploader/phpfileuploader
```

### Simple Example
``` php
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
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:**
``` php
$file = new \PhpFileUploader\Uploader('inputfilename');
$file->path('/files/');
$file->createRandomName(); // Generates random name.
$file->upload();
```

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

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

### 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
* 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
``` php
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
}
}
```
``` html


upload

```