2017 © Pedro Peláez
 

library upload

A great class to upload your file or files to the server, could be integreted with laravel

image

reich/upload

A great class to upload your file or files to the server, could be integreted with laravel

  • Saturday, July 14, 2018
  • by edenreich
  • Repository
  • 2 Watchers
  • 9 Stars
  • 54 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 8 Versions
  • 8 % Grown

The README.md

, (*1)

Upload.php

br/, (*2)

, (*3)

PHP Class for uploading file or files to the server, (*4)

Installing

with composer just run:, (*5)

composer require reich/upload

or, (*6)

You can also download src/Upload.php and simply use it., (*7)

As a Package for Laravel

This class is fully integrated into laravel framework using Laravel Auto-Discovery. If you don't use v5.5+ you may import the necessary files path in your /config/app.php file manually:, (*8)

  ...
    "providers" => [
      /*
       * Package Service Providers...
       */
      Reich\Upload\Laravel\UploadServiceProvider::class,
    ],

    "aliases" => [
      "Upload" => Reich\Upload\Laravel\UploadFacade::class,
    ]
  ...

Usage

1) Copy the class that located in the src directory into your project or install it via composer and use it.
2) Generate an encryption key contains 32 characters or use Reich\Upload::generateMeAKey(); helper.
3) Please open the example /demo/index.php file I created to follow and get a better understanding

Make sure the form is submitted:, (*9)

if(Upload::submitted())
{
  // rest of the code goes here
}

Make an instance of the class, (*10)

$upload = new Upload(YOUR-HTML-INPUT-NAME); 

Set the directory where you want to upload the files, by default it will upload to your main directroy, (*11)

$upload->setDirectory('img/'); 

You may also specify that you want to create this directory if it's not exists, (*12)

$upload->setDirectory('img/')->create(true); 

You can set the rules you want for your upload using the following syntax:, (*13)

$upload->addRules([
        'size' => 2000,
        'extensions' => 'png|jpg|pdf'
]);

or, (*14)

$upload->addRules([
        'size' => 2000,
        'extensions' => ['png', 'jpg', 'pdf']
]);

Set this only if you want to have a encrypt file names(optional for security):, (*15)

$upload->encryptFileNames(true);

You may also specify that you want only certain file type to be encrypted like so:, (*16)

$upload->encryptFileNames(true)->only(['jpg']); // only jpg files will be encrypted

Or also the following syntax:, (*17)

$upload->encryptFileNames(true)->only('jpg|png|txt'); // only jpg, png and txt files will be encrypted

After all is set just run the following command, (*18)

$upload->start();

Events

Whenever a file has been successfully uploaded., (*19)

$upload->success(function($file) {
  // handle the file
});

If something went wrong listen to error., (*20)

$upload->error(function($file) {
  // handle the file
});

Error Handling

Check wether there are errors and if there arent errors, proccess the upload:, (*21)

if($upload->unsuccessfulFilesHas())
{
  // display all errors with bootstraps
  $upload->displayErrors();

  // now of course you may formating it differently like so
  foreach($upload->errorFiles as $file)
  {
    // do whatever you want with the file object
    // - $file->name
    // - $file->encryptedName *only if you asked to encrypt*
    // - $file->type
    // - $file->extension
    // - $file->size
    // - $file->error
    // - $file->errorMessage
  }
}
else if($upload->successfulFilesHas())
{
  $upload->displaySuccess();

  // now of course you may formating it differently like so
  foreach($upload->successFiles as $file)
  {
    // do whatever you want with the file object
    // - $file->name
    // - $file->encryptedName *only if you asked to encrypt*
    // - $file->type
    // - $file->extension
    // - $file->size
  }
}

Here is another method to show you useful errors if something went wrong:

print_r($upload->debug()); // There are some errors only you should look at while setting this up

The Versions

14/07 2018

dev-dev

dev-dev https://github.com/edenreich

A great class to upload your file or files to the server, could be integreted with laravel

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel file upload files

14/07 2018

2.0.x-dev

2.0.9999999.9999999-dev https://github.com/edenreich

A great class to upload your file or files to the server, could be integreted with laravel

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel file upload files

14/07 2018

1.1.x-dev

1.1.9999999.9999999-dev https://github.com/edenreich

A great class to upload your file or files to the server

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

file upload files

14/07 2018

dev-master

9999999-dev https://github.com/edenreich

A great class to upload your file or files to the server, could be integreted with laravel

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

laravel file upload files

10/09 2017

v2.0

2.0.0.0 https://github.com/edenreich

A great class to upload your file or files to the server

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

file upload files

10/09 2017

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/edenreich

A great class to upload your file or files to the server

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

file upload files

09/09 2017

v1.1

1.1.0.0 https://github.com/edenreich

A great class to upload your file or files to the server

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

file upload files

05/05 2017

1.0

1.0.0.0 https://github.com/doctrine/instantiator

A great class to upload your file or files to the server

  Sources   Download

MIT

The Development Requires

file form bootstrap upload files