add file upload function to collection

This commit is contained in:
Jonathan Martz
2023-10-09 18:28:19 +02:00
parent a3ac61ac2d
commit bbe4857b34

View File

@@ -47,6 +47,32 @@ class Collection
return json_decode($response, JSON_FORCE_OBJECT); return json_decode($response, JSON_FORCE_OBJECT);
} }
/**
* @param string $recordId
* @param string $field
* @param string $filepath
* @return void
*/
public function upload(string $recordId, string $field, string $filepath): void
{
$ch = curl_init($this->url . "/api/collections/gallery_media/records/" . $recordId);
curl_setopt_array($ch, array(
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_POSTFIELDS => array(
$field => new \CURLFile($filepath)
)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = array('Content-Type: multipart/form-data');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
// var_dump($response);
}
/** /**
* @param string $email * @param string $email
* @param string $password * @param string $password