<?php
// Test script untuk debug upload
require_once '../includes/auth.php';

if (!isAdmin()) {
    die('Unauthorized');
}

echo "<h2>Upload Test</h2>";

// Test directory permissions
$uploadDir = '../uploads/images/';
echo "Upload Directory: " . realpath($uploadDir) . "<br>";
echo "Directory exists: " . (file_exists($uploadDir) ? 'Yes' : 'No') . "<br>";
echo "Directory writable: " . (is_writable($uploadDir) ? 'Yes' : 'No') . "<br>";

// Test PHP settings
echo "Upload max filesize: " . ini_get('upload_max_filesize') . "<br>";
echo "Post max size: " . ini_get('post_max_size') . "<br>";
echo "Max execution time: " . ini_get('max_execution_time') . "<br>";

// Test URL generation
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
$basePath = str_replace('/admin', '', dirname($_SERVER['PHP_SELF']));
$basePath = rtrim($basePath, '/');

echo "Base URL: " . $protocol . '://' . $host . $basePath . "<br>";

// Simple upload form
?>
<form action="upload_image.php" method="post" enctype="multipart/form-data">
    <input type="file" name="image" accept="image/*">
    <input type="submit" value="Test Upload">
</form>