PHP code example of infw / file-manager
1. Go to this page and download the library: Download infw/file-manager 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-manager example snippets
use InFw\File\BaseMimeTypeFactory;
use InFw\File\GenericFileFactory;
use InFw\File\MimeTypes;
use InFw\Size\BaseSizeFactory;
use InFw\FileManager\BasicStorage;
use InFw\FileManager\UploadToStorage;
$config = [
'root_path' => '/var/file-storage/',
'min_size' => 20,
'max_size' => 140000
];
$factory = new GenericFileFactory(
new BaseMimeTypeFactory(
MimeTypes::IMAGES
),
new BaseSizeFactory(
$config['min_size'],
$config['max_size']
)
);
/** @var \InFw\FileManager\StorageInterface $filesystem */
$filesystem = new BasicStorage($config['root_path']);
$upload = new UploadToStorage($filesystem, $factory);
// Assuming your form has an input type=file field named "upload" and an input type=name named "file_name".
/** @var \InFw\File\FileInterface $file */
$file = $upload->sendToStorage($_FILES['upload'][0]['tmp_name'], $_POST['file_name']);