<?php
define('FCPATH', __DIR__ . '/public/');
require FCPATH . '../app/Config/Paths.php';
$paths = new Config\Paths();
define('WRITEPATH', $paths->writableDirectory . DIRECTORY_SEPARATOR);

$db = new PDO('mysql:host=127.0.0.1;dbname=kopdigi;port=3306', 'root', '');

// Fertilizer alternative image
$imgUrl = "https://images.unsplash.com/photo-1599839619722-39751411ea63?w=500";
$imgData = @file_get_contents($imgUrl);
if ($imgData) {
    $filename = 'product_6_fixed.jpg';
    file_put_contents(WRITEPATH . 'uploads/img/' . $filename, $imgData);
    $newUrl = 'api/products/image/' . $filename;
    $db->exec("UPDATE products SET foto = '$newUrl' WHERE id = 6");
    echo "Product 6 fixed.\n";
} else {
    echo "Failed to get alternative image.\n";
}
