|
|
@@ -25,12 +25,28 @@ switch($request_method) {
|
|
|
$item->readOne();
|
|
|
|
|
|
if($item->name != null) {
|
|
|
+ // Fix picture URL if it contains incorrect path
|
|
|
+ $picture_url = $item->picture;
|
|
|
+ if ($picture_url && strpos($picture_url, '/var/www/html/') !== false) {
|
|
|
+ // Remove /var/www/html/ from the path
|
|
|
+ $picture_url = str_replace('/var/www/html/', '', $picture_url);
|
|
|
+ }
|
|
|
+ if ($picture_url && strpos($picture_url, '/api/') !== false) {
|
|
|
+ // Remove /api/ from the beginning if present
|
|
|
+ $picture_url = str_replace('/api/', '', $picture_url);
|
|
|
+ }
|
|
|
+ // Ensure proper URL format
|
|
|
+ if ($picture_url && !preg_match('/^https?:\/\//', $picture_url)) {
|
|
|
+ $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
|
|
|
+ $picture_url = $baseUrl . '/' . ltrim($picture_url, '/');
|
|
|
+ }
|
|
|
+
|
|
|
$item_arr = array(
|
|
|
"id" => $item->id,
|
|
|
"name" => $item->name,
|
|
|
"description" => $item->description,
|
|
|
"serial_number" => $item->serial_number,
|
|
|
- "picture" => $item->picture,
|
|
|
+ "picture" => $picture_url,
|
|
|
"quantity" => $item->quantity,
|
|
|
"price" => $item->price,
|
|
|
"date_of_purchase" => $item->date_of_purchase,
|
|
|
@@ -55,12 +71,28 @@ switch($request_method) {
|
|
|
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
|
|
extract($row);
|
|
|
|
|
|
+ // Fix picture URL if it contains incorrect path
|
|
|
+ $picture_url = $picture;
|
|
|
+ if ($picture && strpos($picture, '/var/www/html/') !== false) {
|
|
|
+ // Remove /var/www/html/ from the path
|
|
|
+ $picture_url = str_replace('/var/www/html/', '', $picture);
|
|
|
+ }
|
|
|
+ if ($picture && strpos($picture, '/api/') !== false) {
|
|
|
+ // Remove /api/ from the beginning if present
|
|
|
+ $picture_url = str_replace('/api/', '', $picture);
|
|
|
+ }
|
|
|
+ // Ensure proper URL format
|
|
|
+ if ($picture_url && !preg_match('/^https?:\/\//', $picture_url)) {
|
|
|
+ $baseUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
|
|
|
+ $picture_url = $baseUrl . '/' . ltrim($picture_url, '/');
|
|
|
+ }
|
|
|
+
|
|
|
$item_item = array(
|
|
|
"id" => $id,
|
|
|
"name" => $name,
|
|
|
"description" => $description,
|
|
|
"serial_number" => $serial_number,
|
|
|
- "picture" => $picture,
|
|
|
+ "picture" => $picture_url,
|
|
|
"quantity" => $quantity,
|
|
|
"price" => $price,
|
|
|
"date_of_purchase" => $date_of_purchase,
|