Files
dl/tools/crash/upload.php
T
2026-09-16 14:07:40 +08:00

38 lines
1000 B
PHP

<?php
// 保存目录(相对于网站根目录,或写绝对路径)
$saveDir = __DIR__ . '/uploads';
if (!is_dir($saveDir)) {
mkdir($saveDir, 0755, true);
}
$saved = [];
// $_FILES 里是所有上传的文件,不管字段名叫 crashrpt 还是 file
foreach ($_FILES as $field => $file) {
if ($file['error'] !== UPLOAD_ERR_OK) {
continue;
}
// 只取文件名,防路径穿越
$name = basename($file['name']);
if ($name === '') {
continue;
}
// 加时间戳前缀,避免覆盖
$outName = date('Ymd_His') . '_' . $field . '_' . $name;
$outPath = $saveDir . '/' . $outName;
if (move_uploaded_file($file['tmp_name'], $outPath)) {
$saved[] = $outPath;
error_log("[保存] $outPath (" . filesize($outPath) . " bytes)");
}
}
// 记录一下普通表单字段(方便排查)
if (!empty($_POST)) {
error_log("[表单] " . json_encode($_POST, JSON_UNESCAPED_UNICODE));
}
http_response_code(200);
echo "OK";