<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>PHP Upload Limits Check</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 50px auto;
            padding: 20px;
            background: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            border-bottom: 3px solid #667eea;
            padding-bottom: 10px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin: 20px 0;
        }
        th, td {
            padding: 12px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }
        th {
            background: #667eea;
            color: white;
        }
        tr:hover {
            background: #f5f5f5;
        }
        .status-good {
            color: green;
            font-weight: bold;
        }
        .status-warning {
            color: orange;
            font-weight: bold;
        }
        .status-bad {
            color: red;
            font-weight: bold;
        }
        .info-box {
            background: #e7f3ff;
            border-left: 4px solid #2196F3;
            padding: 15px;
            margin: 20px 0;
        }
        .warning-box {
            background: #fff3e0;
            border-left: 4px solid #ff9800;
            padding: 15px;
            margin: 20px 0;
        }
        .success-box {
            background: #e8f5e9;
            border-left: 4px solid #4caf50;
            padding: 15px;
            margin: 20px 0;
        }
        code {
            background: #f5f5f5;
            padding: 2px 6px;
            border-radius: 3px;
            font-family: monospace;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>📊 PHP Upload Limits Check</h1>
        
        <?php
        function return_bytes($val) {
            $val = trim($val);
            $last = strtolower($val[strlen($val)-1]);
            $val = (int)$val;
            switch($last) {
                case 'g': $val *= 1024;
                case 'm': $val *= 1024;
                case 'k': $val *= 1024;
            }
            return $val;
        }
        
        function format_bytes($bytes, $precision = 2) {
            $units = array('B', 'KB', 'MB', 'GB', 'TB');
            
            $bytes = max($bytes, 0);
            $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
            $pow = min($pow, count($units) - 1);
            
            $bytes /= (1 << (10 * $pow));
            
            return round($bytes, $precision) . ' ' . $units[$pow];
        }
        
        function get_status($current_val, $recommended_val, $is_bytes = true) {
            if ($is_bytes) {
                $current = return_bytes($current_val);
                $recommended = return_bytes($recommended_val);
            } else {
                $current = (int)$current_val;
                $recommended = (int)$recommended_val;
            }
            
            if ($current >= $recommended) {
                return '<span class="status-good">✅ Good</span>';
            } elseif ($current >= $recommended * 0.5) {
                return '<span class="status-warning">⚠️ Low</span>';
            } else {
                return '<span class="status-bad">❌ Too Low</span>';
            }
        }
        
        // Get current settings
        $settings = [
            'upload_max_filesize' => ini_get('upload_max_filesize'),
            'post_max_size' => ini_get('post_max_size'),
            'memory_limit' => ini_get('memory_limit'),
            'max_execution_time' => ini_get('max_execution_time'),
            'max_input_time' => ini_get('max_input_time'),
        ];
        
        // Recommended values for 1GB files
        $recommended = [
            'upload_max_filesize' => '1024M',
            'post_max_size' => '1024M',
            'memory_limit' => '1536M',
            'max_execution_time' => '900',
            'max_input_time' => '900',
        ];
        
        // Check if can handle 1GB
        $upload_bytes = return_bytes($settings['upload_max_filesize']);
        $post_bytes = return_bytes($settings['post_max_size']);
        $memory_bytes = return_bytes($settings['memory_limit']);
        
        $can_handle_1gb = ($upload_bytes >= 1073741824 && $post_bytes >= 1073741824);
        
        if ($can_handle_1gb) {
            echo '<div class="success-box">';
            echo '<strong>✅ Your server CAN handle 1GB file uploads!</strong><br>';
            echo 'Maximum file size: ' . format_bytes(min($upload_bytes, $post_bytes));
            echo '</div>';
        } else {
            echo '<div class="warning-box">';
            echo '<strong>⚠️ Your server CANNOT handle 1GB files yet.</strong><br>';
            echo 'Current maximum: ' . format_bytes(min($upload_bytes, $post_bytes)) . '<br>';
            echo 'You need to increase PHP settings (see below).';
            echo '</div>';
        }
        ?>
        
        <h2>Current Settings</h2>
        <table>
            <thead>
                <tr>
                    <th>Setting</th>
                    <th>Current Value</th>
                    <th>Recommended (1GB)</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $byte_settings = ['upload_max_filesize', 'post_max_size', 'memory_limit'];
                
                foreach ($settings as $key => $value) {
                    $is_bytes = in_array($key, $byte_settings);
                    echo '<tr>';
                    echo '<td><strong>' . $key . '</strong></td>';
                    echo '<td>' . htmlspecialchars($value);
                    if ($is_bytes) {
                        echo ' (' . format_bytes(return_bytes($value)) . ')';
                    }
                    echo '</td>';
                    echo '<td>' . $recommended[$key];
                    if ($is_bytes) {
                        echo ' (' . format_bytes(return_bytes($recommended[$key])) . ')';
                    }
                    echo '</td>';
                    echo '<td>' . get_status($value, $recommended[$key], $is_bytes) . '</td>';
                    echo '</tr>';
                }
                ?>
            </tbody>
        </table>
        
        <div class="info-box">
            <h3>💡 How to Increase Limits</h3>
            <p><strong>Method 1: Edit php.ini (Best)</strong></p>
            <p>Find your php.ini file and add/modify:</p>
            <code>
                upload_max_filesize = 1024M<br>
                post_max_size = 1024M<br>
                memory_limit = 1536M<br>
                max_execution_time = 900<br>
                max_input_time = 900
            </code>
            <p style="margin-top: 10px;">Then restart your web server.</p>
            
            <p style="margin-top: 20px;"><strong>Method 2: Use .htaccess (Apache)</strong></p>
            <p>Create/edit .htaccess in your website root:</p>
            <code>
                php_value upload_max_filesize 1024M<br>
                php_value post_max_size 1024M<br>
                php_value memory_limit 1536M<br>
                php_value max_execution_time 900
            </code>
            
            <p style="margin-top: 20px;"><strong>Method 3: Contact Hosting Support</strong></p>
            <p>If you're on shared hosting, contact support to increase these limits.</p>
        </div>
        
        <div class="info-box">
            <h3>🚀 Pro Tip: Use ZIP Compression!</h3>
            <p>Instead of increasing server limits, compress your XML files to ZIP:</p>
            <ul>
                <li>1000 MB XML → ~100 MB ZIP (90% reduction!)</li>
                <li>Faster uploads</li>
                <li>Less server load</li>
                <li>Our importer handles ZIP files automatically</li>
            </ul>
            <p><strong>Example:</strong> <code>zip mydata.zip largefile.xml</code></p>
        </div>
        
        <h2>Additional Information</h2>
        <table>
            <tr>
                <th>Setting</th>
                <th>Value</th>
            </tr>
            <tr>
                <td><strong>PHP Version</strong></td>
                <td><?php echo phpversion(); ?></td>
            </tr>
            <tr>
                <td><strong>Server Software</strong></td>
                <td><?php echo $_SERVER['SERVER_SOFTWARE']; ?></td>
            </tr>
            <tr>
                <td><strong>PHP Configuration File</strong></td>
                <td><?php echo php_ini_loaded_file(); ?></td>
            </tr>
            <tr>
                <td><strong>ZIP Extension</strong></td>
                <td><?php echo class_exists('ZipArchive') ? '<span class="status-good">✅ Enabled</span>' : '<span class="status-bad">❌ Disabled</span>'; ?></td>
            </tr>
            <tr>
                <td><strong>PDO Extension</strong></td>
                <td><?php echo extension_loaded('PDO') ? '<span class="status-good">✅ Enabled</span>' : '<span class="status-bad">❌ Disabled</span>'; ?></td>
            </tr>
            <tr>
                <td><strong>SimpleXML Extension</strong></td>
                <td><?php echo extension_loaded('SimpleXML') ? '<span class="status-good">✅ Enabled</span>' : '<span class="status-bad">❌ Disabled</span>'; ?></td>
            </tr>
        </table>
        
        <div style="margin-top: 30px; padding: 15px; background: #f5f5f5; border-radius: 5px;">
            <p><strong>Need Help?</strong> See <code>LARGE_FILES_GUIDE.md</code> for detailed instructions.</p>
        </div>
    </div>
</body>
</html>
