PHP code example of mohamed-amine / file-uploader

1. Go to this page and download the library: Download mohamed-amine/file-uploader 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/ */

    

mohamed-amine / file-uploader example snippets



// create uploader instance
$file = Upload\Upload('myfile');

// upload files to defined directory
$data = $file->save('myDirectory');

var_dump($data);

// this will output an array which contains uploaded files data
// [
//      'id' => 'sf23s6sdf23s',
//      'name' => 'myFileName',
//      'path' => 'document/images/photo.jpg'
// ]
// 
// Or in case of multi file upload
//
// [
//      [
//          'id' => 'er23sfd3p4uo ',
//          'name' => 'photo1',
//          'path' => 'document/images/photo1.jpg'
//      ],
//      [
//          'id' => 'sf23s6sdf23s',
//          'name' => 'photo2',d
//          'path' => 'document/images/photo2.jpg'
//      ]
// ]
//

$file = Upload\Upload('myfile');

// validate
$file->validate()->extension(['jpg', 'gif'])->size(0.5, 10)->number(2);

// check for validation errors
if ($file->isValide()) {
    var_dump($file->getErrors();
}

// upload files
$file->save('myDirectory');

$file->process()->compress(75)->resize(500, 800)->setName(['firstname', 'secondname']);

// or

$file->process()->compress(75);
$file->process()->resize(500, 800);
$file->process()->setName(['firstname', 'secondname']);

$file->save('myDirectory');