FileUploader!
Presentation
FileUploader is a php class which enables you to upload files on your website !, (*1)
features :
- Upload various type of files. You can choose the allowed formats.
- Rename uploaded files
- Choose location of the uploaded files
- Image resizing
Installation
FileUploader is available via Composer/Packagist, so just add this line to your composer.json file:, (*2)
"pa-bru/file-uploader": "~1.0"
or, (*3)
composer require pa-bru/file-uploader
Usage
Call the class:
$file = $_FILES["myfile"];
$args = [
"fileName" => "my-filename",
"contentDir" => "my-directory/",
"allowedExts" => array(),
"maxSize" => 1000000,
"width" => 200,
"height" => 300
];
$uploader = new FileUploader($file, $args);
$file : File upload data table
$file is required, (*4)
$args : table arguments that can be passed to the constructor
$args is optional. eg: $uploader = new FileUploader($file);, (*5)
Properties
-
fileName : name of file. If not specified, a single string is assigned.
-
contentDir : Destination folder of the file added. The folder is created if it does not exist.
-
allowedExts : Table of allowed extensions.
-
maxSize : The maximum file size in bytes.
-
width : In pixel (px) for resizing images (PNG, JPEG, JPG, GIF).
-
height : In pixel (px) for resizing images (PNG, JPEG, JPG, GIF).
Get the parameters (Getters) :
$uploader->getFileExtension();
- Get the destination path of the file :
$uploader->getPath();
- Get the height to be assigned to the image file :
$uploader->getHeight();
- Get the width to be assigned to the image file :
$uploader->getWidth();
- Get the maximum file size :
$uploader->getMaxSize();
- Get the destination folder of the file :
$uploader->getContentDir();
$uploader->getFileName();
$uploader->getTmpFile();
- Get the allowed extensions for uploading a file :
$uploader->getAllowedExts();
Set the parameters (Setters) :
$uploader->setPath($path);
- Set the height to be assigned to the file (if it is an image) :
$uploader->setHeight($height);
- Set the width to be assigned to the file (if it is an image):
$uploader->setWidth($width);
- Set the maximum size allowed for file upload :
$uploader->setMaxSize($maxSize);
- Set the destination folder of the file :
$uploader->setContentDir($contentDir);
- Set the name to be assigned to the file :
$uploader->setFileName($fileName);
$uploader->setTmpFile($tmpFile);
- Set the table of allowed extensions for file upload :
$uploader->setAllowedExts(array $allowedExts);
Launch upload :
$uploader->upload();
If successful the upload () method returns the path of the uploaded file., (*6)
Releases
v1.0 :
* Initial Version, (*7)
Author
Copyright © 2016 Paul-Adrien Bru | MIT license, (*8)