28 lines
840 B
PHP
28 lines
840 B
PHP
<?php
|
|
require_once __DIR__ . '/../fitness-config.php';
|
|
|
|
function uploadPhotos($provider_id, $files) {
|
|
$url = BASE_API_URL . "/api/providers/$provider_id/photos";
|
|
|
|
$c = curl_init($url);
|
|
curl_setopt($c, CURLOPT_POST, true);
|
|
curl_setopt($c, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
|
|
// Build multipart array
|
|
$multipart = [];
|
|
foreach ($files['tmp_name'] as $i => $tmp) {
|
|
$multipart[] = [
|
|
'name' => 'photos',
|
|
'contents' => fopen($tmp, 'r'),
|
|
'filename' => $files['name'][$i],
|
|
];
|
|
}
|
|
curl_setopt($c, CURLOPT_POSTFIELDS, $multipart);
|
|
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
|
|
|
|
$res = curl_exec($c);
|
|
$http = curl_getinfo($c, CURLINFO_HTTP_CODE);
|
|
curl_close($c);
|
|
|
|
return $http < 400 ? json_decode($res, true) : null;
|
|
}
|
|
?>
|