PHP code example of bera / upload

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

    

bera / upload example snippets



$new_upload = new \Bera\Upload\Upload($_FILES['data']);
$new_upload->setUploadConditon( [
    'file_size' => '20M',
    'allowed_extension' => ['dll','png','jpeg','jpg','pdf']
]);
$new_upload->setUploadDir(__DIR__ . '/upload');
try {
    if($new_upload->upload()) {
        echo 'upload done!';
    } else {
        echo 'upload failed';
    }
}catch ( \Bera\Upload\Exception\FileTypeNotSupprotExectpion $e) {
    echo $e->getMessage();
}catch ( \Bera\Upload\Exception\UplodMaxSizeException $e) {
    echo $e->getMessage();
}