mirror of
https://github.com/grocy/grocy.git
synced 2026-04-08 21:46:16 +02:00
Adapt existing code style
This commit is contained in:
parent
6441615194
commit
762e8ac731
|
|
@ -635,26 +635,27 @@ class StockService extends BaseService
|
||||||
$fileExtension = pathinfo(parse_url($pluginOutput['__image_url'], PHP_URL_PATH), PATHINFO_EXTENSION);
|
$fileExtension = pathinfo(parse_url($pluginOutput['__image_url'], PHP_URL_PATH), PATHINFO_EXTENSION);
|
||||||
|
|
||||||
// Fallback to Content-Type header if file extension is missing
|
// Fallback to Content-Type header if file extension is missing
|
||||||
if (strlen($fileExtension) == 0 && $response->hasHeader('Content-Type')) {
|
if (strlen($fileExtension) == 0 && $response->hasHeader('Content-Type'))
|
||||||
|
{
|
||||||
$fileExtension = explode('+', explode('/', $response->getHeader('Content-Type')[0])[1])[0];
|
$fileExtension = explode('+', explode('/', $response->getHeader('Content-Type')[0])[1])[0];
|
||||||
}
|
}
|
||||||
$imageContent = $response->getBody();
|
|
||||||
|
$imageData = $response->getBody();
|
||||||
}
|
}
|
||||||
else if (preg_match('/data:image\/(\w+?);base64,([A-Za-z0-9+\/]*={0,2})$/',$pluginOutput['__image_url'] ,$matches))
|
elseif (preg_match('/data:image\/(\w+?);base64,([A-Za-z0-9+\/]*={0,2})$/', $pluginOutput['__image_url'], $matches))
|
||||||
{
|
{
|
||||||
$fileExtension = $matches[1];
|
$fileExtension = $matches[1];
|
||||||
if (!($imageContent = base64_decode($matches[2])))
|
if (!($imageData = base64_decode($matches[2])))
|
||||||
{
|
{
|
||||||
unset($imageContent);
|
unset($imageData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($fileExtension) && !empty($imageContent))
|
if (!empty($fileExtension) && !empty($imageData))
|
||||||
{
|
{
|
||||||
$fileName = $pluginOutput['__barcode'];
|
$fileName = $pluginOutput['__barcode'] . '.' . $fileExtension;
|
||||||
$filePath = $fileName . '.' . $fileExtension;
|
file_put_contents($this->getFilesService()->GetFilePath('productpictures', $fileName), $imageData);
|
||||||
file_put_contents($this->getFilesService()->GetFilePath('productpictures', $filePath), $imageContent);
|
$productData['picture_file_name'] = $fileName;
|
||||||
$productData['picture_file_name'] = $filePath;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (\Exception)
|
catch (\Exception)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user