PHP code example of reich / upload

1. Go to this page and download the library: Download reich/upload library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reich / upload example snippets


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

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

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

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

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

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

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

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

$upload->encryptFileNames(true);

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

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

$upload->start();

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

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

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
  }
}

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