<?php
// 最小化上传测试脚本
error_reporting(E_ALL);
ini_set('display_errors', 1);

header('Content-Type: text/plain; charset=utf-8');

echo "=== 上传测试 ===\n";
echo "PHP版本: " . phpversion() . "\n";
echo "上传最大文件大小: " . ini_get('upload_max_filesize') . "\n";
echo "POST最大大小: " . ini_get('post_max_size') . "\n";
echo "临时目录: " . (ini_get('upload_tmp_dir') ?: '系统默认') . "\n";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    echo "\n=== POST数据 ===\n";
    echo "视频类型: " . ($_POST['video_type'] ?? '未设置') . "\n";
    echo "视频名称: " . ($_POST['video_name'] ?? '未设置') . "\n";
    
    echo "\n=== 文件数据 ===\n";
    if (isset($_FILES['video'])) {
        $file = $_FILES['video'];
        echo "文件名: " . $file['name'] . "\n";
        echo "文件类型: " . $file['type'] . "\n";
        echo "文件大小: " . $file['size'] . " bytes\n";
        echo "临时文件: " . $file['tmp_name'] . "\n";
        echo "错误码: " . $file['error'] . "\n";
        
        if ($file['error'] === UPLOAD_ERR_OK) {
            echo "\n文件上传成功!\n";
            // 尝试保存文件
            $uploadDir = 'videos/test/';
            if (!is_dir($uploadDir)) {
                mkdir($uploadDir, 0755, true);
            }
            $newFileName = uniqid() . '.' . pathinfo($file['name'], PATHINFO_EXTENSION);
            if (move_uploaded_file($file['tmp_name'], $uploadDir . $newFileName)) {
                echo "文件保存成功: " . $uploadDir . $newFileName . "\n";
            } else {
                echo "文件保存失败!\n";
            }
        } else {
            $errors = [
                UPLOAD_ERR_INI_SIZE => '文件超过php.ini限制',
                UPLOAD_ERR_FORM_SIZE => '文件超过表单限制',
                UPLOAD_ERR_PARTIAL => '文件部分上传',
                UPLOAD_ERR_NO_FILE => '无文件上传',
                UPLOAD_ERR_NO_TMP_DIR => '缺少临时目录',
                UPLOAD_ERR_CANT_WRITE => '写入失败',
                UPLOAD_ERR_EXTENSION => '扩展阻止'
            ];
            echo "上传错误: " . ($errors[$file['error']] ?? '未知错误') . "\n";
        }
    } else {
        echo "没有文件上传!\n";
    }
} else {
    echo "\n请用POST方法上传文件\n";
}
?>