Confirm raw upload responses

This commit is contained in:
Mikei386
2026-06-23 21:50:34 +02:00
parent 1d8149606a
commit c661cbaf46
6 changed files with 28 additions and 18 deletions
@@ -10,24 +10,14 @@ if (!is_dir($target['path'])) {
if (isset($_GET['relativePath']) || isset($_SERVER['HTTP_X_UNAV_RELATIVE_PATH'])) {
$relativeName = (string)($_GET['relativePath'] ?? $_SERVER['HTTP_X_UNAV_RELATIVE_PATH']);
$destination = unav_prepare_upload_destination($target['path'], $relativeName);
$input = fopen('php://input', 'rb');
$output = fopen($destination['path'], 'xb');
if (!$input || !$output) {
if ($input) {
fclose($input);
}
if ($output) {
fclose($output);
}
unav_error(500, 'Could not open upload stream');
$bytes = file_put_contents($destination['path'], file_get_contents('php://input'), LOCK_EX);
if ($bytes === false) {
unav_error(500, 'Could not store uploaded file');
}
stream_copy_to_stream($input, $output);
fclose($input);
fclose($output);
unav_json([
'uploaded' => [[
'name' => $destination['relative'],
'size' => filesize($destination['path']) ?: 0,
'size' => $bytes,
]],
], 201);
}