implemented upload
This commit is contained in:
@ -76,14 +76,18 @@ class PhotoPrism
|
||||
$result = null;
|
||||
try {
|
||||
if (is_array($data) && $method !== 'post-raw') {
|
||||
$query_data = $content_type === 'application/json' ? json_encode($data) : http_build_query($data);
|
||||
if ($content_type === 'application/json') {
|
||||
$query_data = json_encode($data);
|
||||
} elseif ($content_type === 'multipart/form-data') {
|
||||
$query_data = $data;
|
||||
} else {
|
||||
$query_data = http_build_query($data);
|
||||
}
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
if ($method === 'get' && !empty($query_data)) {
|
||||
$url .= '?'.$query_data;
|
||||
} else {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_data);
|
||||
}
|
||||
if ($method !== 'get') {
|
||||
$headers[] = 'Content-Type: '.$content_type;
|
||||
@ -95,7 +99,7 @@ class PhotoPrism
|
||||
$this->logger->info($method .' request to ' . $url);
|
||||
$this->logger->debug('Headers ' . json_encode($headers));
|
||||
$this->logger->debug('postfields data ' . json_encode($data));
|
||||
$this->logger->debug('postfields ' . $query_data);
|
||||
$this->logger->debug('postfields ' . json_encode($query_data));
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, $method !== 'get');
|
||||
@ -103,6 +107,9 @@ class PhotoPrism
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
|
||||
if ($method !== 'get' && !empty($query_data)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_data);
|
||||
}
|
||||
$output = curl_exec($ch);
|
||||
|
||||
$request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
|
||||
@ -173,5 +180,27 @@ class PhotoPrism
|
||||
return $albums;
|
||||
}
|
||||
|
||||
#https://photos.phlaym.net/api/v1/albums?q=&count=1000&offset=0&type=album
|
||||
public function uploadPhotos(?string $album = null)
|
||||
{
|
||||
$path = time();
|
||||
$url = '/upload/'.$path;
|
||||
$import_url = '/import'.$url;
|
||||
foreach ($_FILES['files']['tmp_name'] as $key => $value) {
|
||||
$file_tmpname = $_FILES['files']['tmp_name'][$key];
|
||||
$this->logger->info('Uploading ' . $file_tmpname . ' to ' . $url);
|
||||
$filename = basename($_FILES['files']['name'][$key]);
|
||||
$cFile = curl_file_create($file_tmpname, $_FILES['files']['type'][$key], $filename);
|
||||
|
||||
$data = ['files' => $cFile];
|
||||
$res = $this->makeRequest('POST', $url, $data, 'multipart/form-data');
|
||||
$this->logger->info('Upload result: ' . $res);
|
||||
}
|
||||
|
||||
$this->logger->info('Importing files');
|
||||
$albums = empty($album) ? [] : [$album];
|
||||
|
||||
$import_data = ["move" => true, "albums" => $albums];
|
||||
$res = $this->makeRequest('POST', $import_url, $import_data);
|
||||
$this->logger->info('Import result: ' . $res);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user