Confirm raw upload responses
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user