PHP code example of mmdm / sim-file

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

    

mmdm / sim-file example snippets

 
composer 



// create new Download instance
$download = new Download($path_to_your_file);
$download->download($your_new_name);

// or just use static function
$download = Download::makeDownloadFromPath($path_to_your_file);
$download->download($your_new_name);

$fileUpload = new FileUpload($the_key_of_file_in_file_global_variable);

// new size validation instance
$sizeValidation = new SizeValidation('2MB', '1MB');

// create new Upload instance
$upload = new Upload();
$upload->upload($your_new_destination);

$files = $fileSystem->getAllFiles();
$files->rewind();
while ($files->valid()) {
  /**
  * @var SplFileInfo $file
  */ 
  $file = $files->current();
  
  // do whatever you need with that file
  
  $files->next();
}

[
  'extension' => 'Specified extension is not allowed!'
]

[
  'mimetype' => 'Specified mimetype is not allowed!',
]

[
  'gt_size' => 'File size is greater than allowed file size!',
  'lt_size' => 'File size is less than allowed file size!',
]

// new extension filterer instance
// pass array of allowed extensions without dot
$extFilter = new ExtensionFilter(['png', 'jpg', 'jpeg']);

// new mimetype filterer instance
// pass array of allowed mimetypes
$mimetypeFilter = new MimeTypeFilter(['image/png', 'image/jpg']);

// new name filterer instance
// files that name of them ends with 'es'
$nameFilter = new NameFilter('/es$/i');

// new size filterer instance
$sizeFilter = new SizeFilter('2MB', '1MB');

// new type filterer instance
$typeFilter = new TypeFilter(IFileSystem::TYPE_FILE | IFileSystem::TYPE_DIRECTORY);

// new regex filterer instance
$regexFilter = new RegexFilter('/es\.(png|jpe?g|gif)$/i');

// new extension validation instance
// pass array of allowed extensions without dot
$extValidation = new ExtensionValidation(['png', 'jpg', 'jpeg']);

// new mimetype validation instance
// pass array of allowed mimetypes
$mimetypeValidation = new MimeTypeValidation(['image/png', 'image/jpg']);