PHPackages                             hamrocdn/sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hamrocdn/sdk

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

hamrocdn/sdk
============

SDK for HamroCDN - A CDN service provider

v1.1.1(6mo ago)0399MITPHPPHP &gt;=8.0

Since Oct 28Pushed 6mo agoCompare

[ Source](https://github.com/HamroCDN/php-sdk)[ Packagist](https://packagist.org/packages/hamrocdn/sdk)[ Docs](https://hamrocdn.com)[ Fund](https://www.buymeacoffee.com/achyutn)[ GitHub Sponsors](https://github.com/achyutkneupane)[ RSS](/packages/hamrocdn-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (4)Used By (0)

HamroCDN PHP SDK
================

[](#hamrocdn-php-sdk)

[![Lint & Test PR](https://github.com/HamroCDN/php-sdk/actions/workflows/prlint.yml/badge.svg)](https://github.com/HamroCDN/php-sdk/actions/workflows/prlint.yml)[![Quality Gate Status](https://camo.githubusercontent.com/f6179e635311c5d156696f46a16c8062c4305b5f2fd211b6f697f75f938c9955/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d48616d726f43444e5f7068702d73646b266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=HamroCDN_php-sdk)

> **Official PHP SDK for HamroCDN** — a simple, typed, and framework-agnostic way to upload, fetch, and manage files from your HamroCDN account.

---

📦 Installation
--------------

[](#-installation)

Install via [Composer](https://getcomposer.org/):

```
composer require hamrocdn/sdk
```

### Requirements

[](#requirements)

- PHP **8.0+**
- [GuzzleHTTP](https://github.com/guzzle/guzzle) 7.10+

That’s it.
No Laravel dependencies, no magic — just pure PHP.

---

⚙️ Configuration
----------------

[](#️-configuration)

You can pass your API key directly, or rely on environment/config values if available.

```
use HamroCDN\HamroCDN;

$cdn = new HamroCDN('your-api-key');
```

Alternatively, if your environment has them:

```
export HAMROCDN_API_KEY="your-api-key"
```

the SDK automatically detects and uses them.

---

⚡ Quick Start
-------------

[](#-quick-start)

Here’s a quick example showing upload and fetch in action:

```
use HamroCDN\HamroCDN;

$cdn = new HamroCDN('your-api-key');

// Upload a file
$upload = $cdn->upload('/path/to/image.jpg');

echo "Uploaded: " . $upload->getOriginal()->getUrl() . PHP_EOL;

// Fetch it again
$fetched = $cdn->fetch($upload->getNanoId());

echo "Fetched: " . $fetched->getOriginal()->getUrl() . PHP_EOL;
```

---

🚀 Usage
-------

[](#-usage)

This SDK make use of [public API](https://hamrocdn.com/docs/api) provided by HamroCDN. To get your API key, sign up at [hamrocdn.com](https://hamrocdn.com/dashboard) and navigate to *Edit Profile* page in your dashboard.

### 1. List Uploads

[](#1-list-uploads)

#### 1.1 Paginated

[](#11-paginated)

The `index()` method returns paginated results.
You can provide pagination parameters such as `page` and `per_page`:

```
$uploads = $cdn->index(page: 1, per_page: 10);

foreach ($uploads->all() as $upload) {
    echo $upload->getNanoId() . ' - ' . $upload->getOriginal()->getUrl() . PHP_EOL;
}
```

> Returns an object containing `data` (array of `Upload` models) and `meta` (pagination info).

Example of returned metadata:

```
{
  "meta": {
    "total": 120,
    "per_page": 10,
    "page": 1
  }
}
```

#### 1.2 All Uploads

[](#12-all-uploads)

To fetch all uploads without pagination, use the `all()` method:

```
$uploads = $cdn->all();
foreach ($uploads as $upload) {
    echo $upload->getNanoId() . ' - ' . $upload->getOriginal()->getUrl() . PHP_EOL;
}
```

> Returns an array of `Upload` models.

---

### 2. Fetch a Single Upload

[](#2-fetch-a-single-upload)

```
$upload = $cdn->fetch('abc123');

echo $upload->getOriginal()->getUrl(); // https://hamrocdn.com/abc123/original
```

---

### 3. Upload a File

[](#3-upload-a-file)

```
$upload = $cdn->upload('/path/to/image.png');

echo $upload->getNanoId(); // nano ID of the uploaded file
```

> To delete the file after a certain time, use the `deleteAfter` parameter (in seconds):

```
$upload = $cdn->upload('/path/to/image.png', deleteAfter: 3600); // Deletes after 1 hour
```

> This will set the `deleteAt` property on the returned `Upload` model.

---

### 4. Upload by Remote URL

[](#4-upload-by-remote-url)

```
$upload = $cdn->uploadByURL('https://example.com/image.png');

echo $upload->getOriginal()->getUrl();
```

> Also supports the `deleteAfter` parameter.

---

🧱 Models
--------

[](#-models)

### 🗂 `HamroCDN\Models\Upload`

[](#-hamrocdnmodelsupload)

PropertyTypeDescription`nanoId``string`Unique identifier of the upload`user``User` or `null`Owner of the file (if authenticated)`deleteAt``Carbon` or `null`Deletion timestamp if temporary`original``File`File information (URL, size)#### Methods

[](#methods)

- `getNanoId()`: `string`
- `getUser()`: `?User`
- `getDeleteAt()`: `?Carbon`
- `getOriginal()`: `File`
- `toArray()`: `array`

---

### 👤 `HamroCDN\Models\User`

[](#-hamrocdnmodelsuser)

PropertyTypeDescription`name``string`Name of the uploader`email``string`Email of the uploader#### Methods

[](#methods-1)

- `getName()`: `string`
- `getEmail()`: `string`
- `toArray()`: `array`

---

### 🧾 `HamroCDN\Models\File`

[](#-hamrocdnmodelsfile)

PropertyTypeDescription`url``string`Public CDN URL`size``int`File size in bytes#### Methods

[](#methods-2)

- `getUrl()`: `string`
- `getSize()`: `int`
- `toArray()`: `array`

---

⚡ Error Handling
----------------

[](#-error-handling)

All SDK errors extend `HamroCDN\Exceptions\HamroCDNException`.

Example:

```
use HamroCDN\Exceptions\HamroCDNException;

try {
    $cdn->upload('/invalid/path.jpg');
} catch (HamroCDNException $e) {
    echo 'Upload failed: ' . $e->getMessage();
}
```

The SDK automatically wraps:

- Network issues (`GuzzleException`)
- Invalid JSON responses
- Missing API key or misconfiguration

---

🧪 Testing
---------

[](#-testing)

This SDK is built with [Pest](https://pestphp.com/) and supports **real API integration tests**.
A dedicated testing environment is configured within the HamroCDN infrastructure, ensuring safe, production-like validations.

Run tests locally:

```
composer test
```

---

🪄 Framework Integrations
------------------------

[](#-framework-integrations)

This SDK is **framework-agnostic**. If you’re using **Laravel**, check out the companion package:

👉 [**hamrocdn/laravel**](https://packagist.org/packages/hamrocdn/laravel)

It provides service providers, configuration publishing, and automatic Facade binding.

---

🧩 Type Safety / Static Analysis
-------------------------------

[](#-type-safety--static-analysis)

- Fully typed with PHPStan annotations
- 100% PHP 8.0+ compatible
- Pint with `laravel` preset for code style
- Rector for automated refactoring
- SonarCloud integration for code quality

---

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please create a pull request or open an issue if you find any bugs or have feature requests.

---

⭐ Support
---------

[](#-support)

If you find this package useful, please consider starring the repository on GitHub to show your support.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance66

Regular maintenance activity

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

202d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/52259760?v=4)[achyutn](/maintainers/achyutn)[@AchyutN](https://github.com/AchyutN)

---

Top Contributors

[![achyutkneupane](https://avatars.githubusercontent.com/u/30431426?v=4)](https://github.com/achyutkneupane "achyutkneupane (83 commits)")

---

Tags

cdnhacktoberfestlaravelphpsdkphplaravelsdkcdnhamrocdn

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hamrocdn-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/hamrocdn-sdk/health.svg)](https://phpackages.com/packages/hamrocdn-sdk)
```

###  Alternatives

[stevebauman/location

Retrieve a user's location by their IP Address

1.3k7.6M65](/packages/stevebauman-location)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[amranidev/laracombee

Recommendation system for laravel

11636.7k1](/packages/amranidev-laracombee)[willywes/agora-sdk-php

Agora.io SDK PHP

1023.2k2](/packages/willywes-agora-sdk-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
