PHP code example of ruvents / spiral-upload

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

    

ruvents / spiral-upload example snippets


use Ruvents\SpiralUpload\UploadBootloader;

class App extends Kernel
{
    protected const LOAD = [
        ...
        UploadBootloader::class,
    ]
}



declare(strict_types=1);

return [
    'uploadClass' => Upload::class, // Custom UploadInterface implementation class.
    'urlPrefix' => 'https://foo.bar/uploads/', // Public URL to uploads. Example:
    // https://foo.bar/uploads/f8/some-upload.png -- full URL to upload
    // https://foo.bar/uploads -- URL prefix
    // f8/some-upload.png -- relative path to upload
];

public function manageUploads(UploadManager $manager)
{
    // Create upload from file path.
    $upload = $manager->create('/path/to/file.txt', 'file.txt');

    // Create upload from resource.
    $upload = $manager->create($handle = fopen('/path/to/file.txt', 'r'), 'file.txt');
    fclose($handle);

    // Or from UploadedFileInterface.
    $stream = clone $uploadedFile->getStream();
    $upload = $manager->create($stream->detach(), 'file.txt');

    // Get full URL of upload.
    $url = $manager->url($upload);

    // Delete stored file associated with upload.
    $manager->delete($upload);
}