alirdn/os-project/SecureUPload

SecureUPload featured image

SecureUPload – PHP secure file upload package


SecureUPload is a PHP composer package to securely upload files. SecureUPload uses best practices for uploading files in PHP, so you can use it without any file upload security headaches. Furthermore, it’s flexible enough that fits to most of different projects structures.

Why SecureUPload?


File upload is a risky part in all web applications. There are multiple ways that an attacker could attack web application by file upload feature. So whenever a web application wants to add this feature, developers needs to write lots of code for make it risk free. But file uploads could be secure, if we don’t trust users provided data (including HTTP headers and files) and check everything carefully. For more information about file upload risks please see: OWAP Unrestricted File Upload SecureUPload uses best practices steps for making a file upload secure. By using SecureUpload package, developer can focuses on other aspects of project and be sure about file uploads.

Features


  • Single and multiple input file/files upload support
  • Support storing uploaded files in different location. For more info see storage_type SecureUPloadConfig section
  • Support different uploaded files organization
  • Configure accepted upload file types and minimum/maximum file size globally or upload specific
  • Zero dependency for production
  • Different error codes for invalid uploaded files for better error handling

Installation


Because SecureUPload has zero dependency, it can be installed as a composer package, or without composer and as a PHP library.

Install as composer package

$ composer install alirdn/secureupload

Install as PHP library

You must download it from SecureUPload github page or Download Latest link above. Then unzip it and include src/autoloader.php file in your PHP project. All done!

Basic Usage


<?php
use Alirdn\SecureUPload\Config\SecureUPloadConfig;
use Alirdn\SecureUPload\SecureUPload;
// Create SecureUPloadConfig and set Uploaded files folder
$SecureUPloadConfig = new SecureUPloadConfig;
$SecureUPloadConfig->set( 'upload_folder', 'uploads' . DIRECTORY_SEPARATOR );
// Create SecureUPload and give previously created config to it
$SecureUPload = new SecureUPload( $SecureUPloadConfig );
// Upload a file
$Upload = $SecureUPload->uploadFile( 'file' );
// Check uploaded file
if ( $Upload->status ) {
// File has been set in <input type="file" name="file"/>
if ( $Upload->status == 1 ) {
echo 'File uploaded successfully. Id: ' . $Upload->id;
} else {
echo 'File didn\'t uploaded. Error code: ' . $Upload->error;
}
} else {
// No file is selected in input field
}
view raw basic-usage.php hosted with ❤ by GitHub

Documentation


Requirements


SecureUPload works with PHP 5.3.0 and above.

Bugs & feature requests


For submitting bugs or feature requests, use project Github repository issues.

Todos


  • Add virus scan services API
  • Add save to database feature

License


SecureUPload is licensed under MIT License. see the LICENSE file for details.

Author


  • Alireza Dabiri Nejad – Alirdn

Acknowledgements