Official PHP SDK for the YourImageShare
upload API. Zero Composer dependencies (uses PHP's own curl extension),
PHP 7.4+.
- Get an API key: sign in and open the API tab at yourimageshare.com/my-account.
- Full HTTP reference: yourimageshare.com/about/api or API.md in the yourimageshare-api repo.
- Same API, same result shapes, in JavaScript/TypeScript and Python too.
composer require yourimageshare/yourimageshare-phpuse YourImageShare\YourImageShare;
$client = new YourImageShare('YOUR_API_KEY');
// Upload a file by path
$result = $client->upload('photo.jpg');
echo $result->direct; // https://yourimageshare.com/ib/aB3xY9qRz1
// Upload with auto-delete after 1 hour
$client->upload('photo.jpg', ['expires_in' => 3600]);
// Upload from an already-open resource
$handle = fopen('photo.jpg', 'rb');
$client->upload($handle, ['filename' => 'photo.jpg']);
// List your uploads (paginated, 50 per page)
$listing = $client->list();
foreach ($listing->data as $item) {
echo $item->id . ' ' . $item->direct . PHP_EOL;
}
// Delete an upload
$client->delete($result->id);Failed requests throw YourImageShare\YourImageShareError
(getStatus() is the HTTP status code, getApiMessage() is the server's
error text):
use YourImageShare\YourImageShare;
use YourImageShare\YourImageShareError;
$client = new YourImageShare('YOUR_API_KEY');
try {
$client->upload('photo.jpg');
} catch (YourImageShareError $e) {
echo $e->getStatus() . ': ' . $e->getApiMessage();
}new YourImageShare(string $apiKey, string $baseUrl = YourImageShare::DEFAULT_BASE_URL, int $timeout = 30)
$baseUrl defaults to https://yourimageshare.com/api - override only for
testing against a different environment.
$file is a path (string) or an open resource (from fopen()).
$options['expires_in'] is seconds, 60 to 2,592,000 (30 days) - omit for a
permanent upload. $options['filename'] is required when $file is a
resource without an obvious name. Returns an UploadResult with id,
type, path, src, direct, expiresAt.
Returns a ListResult with data (an array of ListedUpload - id,
type, title, path, src, direct, expiresAt, createdAt) and
meta (ListMeta - currentPage, lastPage, total).
Throws YourImageShareError on a 404/401; returns void on success.
20 requests/minute and 500/day per key by default (2,000/day per IP as a
backstop). Not currently surfaced on the return values from this SDK - read
the X-RateLimit-Limit/X-RateLimit-Remaining response headers yourself if
you need them, or open an issue to request them on the result objects.
MIT