1. Go to this page and download the library: Download devhammed/byteship-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/ */
devhammed / byteship-php example snippets
use Devhammed\Byteship\Client;
$byteship = new Client(apiKey: $_ENV['BYTESHIP_API_KEY']);
use Devhammed\Byteship\Client;
$byteship = new Client(uploadToken: 'bsut_...');
use Devhammed\Byteship\Client;
use Devhammed\Byteship\Enums\Visibility;
use Devhammed\Byteship\ValueObjects\UploadProgress;
$byteship = new Client(apiKey: $_ENV['BYTESHIP_API_KEY']);
$file = fopen('photo.jpg', 'rb');
$uploaded = $byteship->upload(
$file,
path: 'uploads/photo.jpg',
visibility: Visibility::Public,
metadata: [
'user_id' => '123',
],
onProgress: function (UploadProgress $progress) {
echo round($progress->percent).'% uploaded';
},
);
echo "#{$uploaded->id} - {$uploaded->url}";
use Devhammed\Byteship\Client;
use Devhammed\Byteship\Enums\Visibility;
use Devhammed\Byteship\Enums\UploadManyResultStatus;
use Devhammed\Byteship\ValueObjects\UploadManyProgress;
use Devhammed\Byteship\ValueObjects\UploadInput;
$byteship = new Client(apiKey: $_ENV['BYTESHIP_API_KEY']);
$files = [
new UploadInput(fopen('photo-1.jpg', 'rb')),
new UploadInput(fopen('photo-2.jpg', 'rb')),
new UploadInput(fopen('photo-3.jpg', 'rb')),
new UploadInput(fopen('photo-4.jpg', 'rb')),
new UploadInput(fopen('photo-5.jpg', 'rb')),
new UploadInput(fopen('photo-6.jpg', 'rb')),
];
$results = $byteship->uploadMany(
$files,
concurrency: 3,
pathPrefix: 'gallery',
visibility: Visibility::Public,
metadata: [
'user_id' => '123',
],
onFileProgress: function (UploadManyProgress $progress) {
echo '#'.$progress->index.': '.round($progress->percent).'% uploaded';
},
);
$uploaded = array_map(
fn($item) => $item->result,
array_filter($results, fn($item) => $item->status === UploadManyResultStatus::Fulfilled),
);