PHP code example of mochrira / selvi-files

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

    

mochrira / selvi-files example snippets


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();