mirror of
https://github.com/jonathan-martz/pocketbase-php-sdk.git
synced 2026-04-02 23:17:43 +00:00
add file upload function to collection
This commit is contained in:
@@ -47,6 +47,32 @@ class Collection
|
||||
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 $password
|
||||
|
||||
Reference in New Issue
Block a user