1. Go to this page and download the library: Download tcb13/thunder-tus-php 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/ */
tcb13 / thunder-tus-php example snippets
uest = Zend\Diactoros\ServerRequestFactory::fromGlobals();
$response = new Zend\Diactoros\Response();
$backend = new FileSystem(__DIR__ . DIRECTORY_SEPARATOR . "uploads");
$server = new ThunderTUS\Server($request, $response);
$server->setStorageBackend($backend);
$server->setApiPath("/");
$server->handle();
$response = $server->getResponse();
$emitter = new Zend\HttpHandlerRunner\Emitter\SapiEmitter();
$emitter->emit($response);
$finalStorageDirectory = "/var/www/html/uploads";
$server = new ThunderTUS\Server();
$status = $server->completeAndFetch($filename, $finalStorageDirectory);
if (!$status) {
throw new \Exception("Could not fetch ({$filename}) from storage backend: not found.");
}
// Connect to your MongDB
$con = new \MongoDB\Client($configs->uri, $configs->options]);
$mongodb= $con->selectDatabase($configs->db]);
// Start ThunderTUS
$server = new \ThunderTUS\Server($request, $response);
// Load the MongoDB backend
$mongoBackend = new MongoDB($mongodb);
$server->setStorageBackend($mongoBackend );
// Set other settings and process requests
$server->setUploadMaxFileSize(50000);
$server->setApiPath("/tus");
$server->handle();
// Send the response back to the client
$response = $server->getResponse();
$server = new \ThunderTUS\Server($request, $response);
$redisBackend = new Redis($redisClient);
$server->setStorageBackend($redisBackend);
$server->setUploadMaxFileSize(50000);
$server->setApiPath("/tus");
$server->handle();
public static function register()
{
$settings = $this->container->get("settings.tusProtocol");
// Create the server
$server = new Server(); // No request or response implementations passed here
// Load the filesystem Backend
$backend = new FileSystem($settings->path]);
$server->setStorageBackend($backend);
// Set TUS upload parameters
$server->setUploadMaxFileSize((int)$settings->maxSize);
$server->setApiPath($settings->endpoint);
return $server;
}
public function upload()
{
// Resolve TUS using the container
/** @var \ThunderTUS\Server $server */
$server = $this->container->get(\ThunderTUS\Server::class);
// Load the request or response implementations here!
$server->loadHTTPInterfaces($this->request, $this->response);
// Handle the upload request
$server->handle();
// Send the response back to the client
return $server->getResponse();
}
shell
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.