PHP code example of infw / file

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

    

infw / file example snippets




use InFw\File\BaseMimeTypeFactory;
use InFw\Size\BaseSizeFactory;
use InFw\File\MimeTypes;
use InFw\File\GenericFileFactory;

$config = [
    'min_size' => 20,
    'max_size' => 140000
];

$mime = new BaseMimeTypeFactory(
    MimeTypes::IMAGES
);

$size = new BaseSizeFactory(
    $config['min_size'],
    $config['max_size']
);

// Assuming your form has an input type=file field named "upload" and an input type=name named "file_name".
$fileFactory = new GenericFileFactory($mime, $size);

/** @var \InFw\File\FileInterface $file */
$file = $fileFactory->make($_FILES['upload'][0]['tmp_name'], $_POST['file_name']);

$file->getName();
$file->getMimeType();
$file->getSize();
$file->getTmpName();