<?php
function uploadFiles(string $url, array $files, array $fields = []): string {
$payload = $fields;
foreach ($files as $name => $path) {
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($path);
$payload[$name] = new CURLFile($path, $mime ?: 'application/octet-stream', basename($path));
}
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
]);
$resp = curl_exec($ch);
if ($resp === false) throw new RuntimeException('Upload failed: ' . curl_error($ch));
curl_close($ch);
return $resp;
}
$resp = uploadFiles('https://api.example.com/avatar', ['avatar' => '/tmp/pic.png'], ['user_id' => '42']);
Create a free account and build your private vault. Share publicly whenever you want.