infw/file-manager

File Manager for In Framework

0.0.1.2 2016-10-27 22:24 UTC

This package is auto-updated.

Last update: 2024-10-18 09:34:55 UTC


README

Scrutinizer Code Quality Code Coverage Build Status

File manager provides a basic system storage for files, It uses "In Framework" File object as DTO.

It has a SendToStorage service to persist files in filesystem.

Installation:

composer require infw/file-manager

Usage:

<?php

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']);