Giter Site home page Giter Site logo

php-file-uploader's Introduction

FILE UPLOADER

FIle Uploader is a php package to aid fast , easy and safe file upload

installation

composer require codad5/file-helper

Features

  • Fast and easy to use with method chaining
  • Good error management
  • Safety management
  • works for both multiple file upload and single file upload

Usage

index.php

<form action="./upload.php" method='post' enctype="multipart/form-data">
    <input type="file" name="test[]" multiple>
    <input value="submit" type="submit">
</form>

upload.php

<?php
    include(__DIR__ . '/../vendor/autoload.php');
    
    $file_upload_controller = new Codad5\FileHelper\FileUploader('test', "uploads/");

test - the name given to the $_FILES array by default - for refrence $_FILES['test]`

uploads/ - Upload path relative to upload.php

To add allowed extension

#any other extension aid the given will give error or ignored depending on your error settings
$file_upload_controller->add_ext('svg', 'png');

To set File Prefix

# for unique id can be replaced with uniqid('', true)
$file_upload_controller->set_prefix('my prefix');

To set max and min size

$file_upload_controller->set_sizes(10000, 20);

10000 - This is the maximum file size allowed, to ignore for your .ini config set it to null 20 - This is the minimum file size allowed default equals 0

Turing on/Off Error reporting

/**
 * This is use to turn on and off reporting of the upload process
 * @param bool $file_error - to report error imbound in file from request if `true` else ignore
 * @param bool $size_error - TO report size related error if `true` else ignore
 * @param bool $type_error - To report error related to file type if `true` else ignore
 */
$file_upload_controller->set_reporting(true, false, true);
  • The first param $file_error is to report error imbounded in file from request as found in $_SERVER['test']
  • The second param $size_error is to report size related error depending on your settings
  • The Third param $type_error is to report error if a file is not part of the allowed file

NOTE: If any is false and error is found it will ignore the file and continue upload with out the file

Moving the file

$file_upload_controller->move_files();

Get Uploaded file path

$upload_path = $file_upload_controller->get_uploads();

foreach ($upload_path as $key => $value) {
        # code...
        echo "This file has been uploaded to ".$value['uploaded_path']."<br/>;
    }
  • This returns a multi-dimensional array of each array with the following key
  • uploaded_path - The final uploaded file with path relative to the script tag upload.php
  • name - The name of the file
  • size - The size of the file
  • type - The file Type
  • ext - The file extension

Method Chaining

$file_upload_controller = new \Codad5\FileHelper\FileUploader('tes', "uploads/");

    $uploaded_file_array = $file_upload_controller
    ->set_reporting(false, false, false)
    ->add_ext('png', 'pdf')
    ->set_prefix('cool Stuff')
    ->move_files()
    ->get_uploads();

    foreach ($uploaded_file_array as $key => $value) {
        # code...
        echo "This file has been uploaded to ".$value['uploaded_path']."<br/>";
    }

This documentaion will be updated in time as the project grows for enquire and more information contact me here

Built with ๐Ÿ’— by Chibueze Michael A.

php-file-uploader's People

Contributors

codad5 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.