1. Go to this page and download the library: Download hernol/uploadthing-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/ */
hernol / uploadthing-php example snippets
use UploadThing\Resources\Uploads;
$uploads = new Uploads();
$file = $uploads->uploadFile('/path/to/file.jpg');
if ($file) {
echo "File uploaded: {$file->name}\n";
echo "File URL: {$file->url}\n";
echo "File ID: {$file->id}\n";
}
use UploadThing\Resources\Uploads;
$uploads = new Uploads();
$file = $uploads->uploadFile(
'/path/to/image.jpg',
'my-custom-name.jpg',
'image/jpeg'
);
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use UploadThing\Resources\Uploads;
use UploadThing\Resources\Webhooks;
class UploadThingServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->singleton(Uploads::class, function () {
return new Uploads();
});
$this->app->singleton(Webhooks::class, function () {
return new Webhooks();
});
}
}
namespace App\Http\Controllers;
use UploadThing\Resources\Uploads;
use Illuminate\Http\Request;
class FileController extends Controller
{
public function upload(Request $request, Uploads $uploads)
{
$file = $request->file('file');
$uploaded = $uploads->uploadFile(
$file->getPathname(),
$file->getClientOriginalName(),
$file->getMimeType()
);
return response()->json(['file' => $uploaded]);
}
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.