mochrira/selvi-files

There is no license information available for the latest version (0.1.6) of this package.

Library untuk upload file ke selvi framework

0.1.6 2021-02-11 05:57 UTC

This package is auto-updated.

Last update: 2024-12-11 13:51:54 UTC


README

This is library to upload and download files with selvi framework.

Requirements

  • php^7.4
  • php_fileinfo module
  • mochrira/selvi-framework^0.3.12

Installing

composer require mochrira/selvi-files

Usage

namespace App\Controllers;
use Selvi\Controller;
use Selvi\Files;

class UploadController extends Controller {

    function upload() {
        $this->load(Files::class, 'files');
        $result = $this->files->upload('file', [
            'allowedTypes' => ['image/jpg', 'image/jpeg', 'image/gif'],
            'path' => 'images',
            'maxSize' => 1000000
        ]);
        return jsonResponse($result);
    }

    function download() {
        $uri = $this->uri->getUri();
        if(strpos($uri, '/download') == 0) {
            $uri = preg_replace('/'.preg_quote('/download/', '/').'/', '', $uri, 1);
        }
        $this->load(Files::class, 'files');
        $this->files->download($uri);
    }

}

\Selvi\Files::setup([
    'basePath' => __DIR__.'/files'
]);
\Selvi\Route::post('/upload', 'UploadController@upload');
\Selvi\Route::post('/download', 'UploadController@download');
\Selvi\Framework::run();