Start free trial

Extensions (PHP) · Uploads and payments

Uploads and payments

Uploads

Store files through your extension's storage, never straight on the disk. Files land in the extension's own folder on that forum and count towards the forum's storage.

$path = $this->storage()->storeUpload('photos', $request->file('photo'));

$url = $this->storage()->url($path);

Unsafe file types are refused. Pass the types you accept and a size limit in kilobytes as the third and fourth arguments; by default it accepts jpg, png, gif, webp, pdf, txt, zip, mp3 and mp4 up to 10 MB. When an admin uninstalls the extension and chooses to delete its data, the folder is removed too.

Charging members

An extension can sell something to a member, like a featured pin. charge creates an invoice the member pays with the forum's own payment settings.

$invoice = $this->charge($user, 'Featured pin for 30 days', 499, 'pin-'.$pin->id, returnPath: ext_route('harbour/member-map', 'map'));

return redirect(board_route('billing.pay', $invoice));

When the payment comes in, ForumSpark calls your class:

public function purchasePaid(ExtensionPurchase $purchase): void
{
}

public function purchaseRefunded(ExtensionPurchase $purchase): void
{
}

If the extension was off when the member paid, the purchase is delivered the next time it is turned on.

Calling other websites

Use $this->http() instead of your own HTTP client. It has timeouts, refuses addresses inside the server's own network, and is what the check expects.