Files
Testing/tus-php/example/basic/verify.php
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

48 lines
1.2 KiB
PHP

<?php
/**
* Sends HEAD request to figure out uploaded offset
* if the file was uploaded partially previously.
*/
require __DIR__ . '/../../vendor/autoload.php';
use TusPhp\Exception\FileException;
use GuzzleHttp\Exception\ConnectException;
$client = new \TusPhp\Tus\Client('http://tus-php-server');
$uploadKey = uniqid('tus_file_');
try {
$offset = $client->setKey($uploadKey)->getOffset();
$status = false !== $offset ? 'resume' : 'new';
$offset = false === $offset ? 0 : $offset;
echo json_encode([
'status' => $status,
'bytes_uploaded' => $offset,
'upload_key' => $uploadKey,
]);
$myfile = fopen("newfile.txt", "a") or die("Unable to open file!");
$txt = $status." sucess?\n".$offset."\n";
fwrite($myfile, $txt);
} catch (ConnectException $e) {
echo json_encode([
'status' => 'error',
'bytes_uploaded' => -1,
]);
$myfile = fopen("newfile.txt", "a") or die("Unable to open file!");
$txt = "error?\n";
fwrite($myfile, $txt);
} catch (FileException $e) {
echo json_encode([
'status' => 'resume',
'bytes_uploaded' => 0,
'upload_key' => '',
]);
$myfile = fopen("newfile.txt", "a") or die("Unable to open file!");
$txt = "what?\n";
fwrite($myfile, $txt);
}