scratch

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 57  →  ?path2? @ 56
/file.php
@@ -14,21 +14,13 @@
#### Retrieve uploaded file.
if (!empty($_FILES['file']) and
is_uploaded_file($_FILES['file']['tmp_name'])) {
if($_FILES['file']['size'] > $ALLOWED_ASSET_SIZE * 1048576) {
header('File size exceeds '.$ALLOWED_ASSET_SIZE.'MiB.', true, 403);
return;
}
# Regular multipart/form-data upload.
$name = $_FILES['file']['name'];
$data = atomized_get_contents($_FILES['file']['tmp_name']);
$data = file_get_contents($_FILES['file']['tmp_name']);
} else {
if((int)get_file_size("php://input") > $ALLOWED_ASSET_SIZE * 1048576) {
header('File size exceeds '.$ALLOWED_ASSET_SIZE.'MiB.', true, 403);
return;
}
# Raw POST data.
$name = urldecode(@$_SERVER['HTTP_X_FILE_NAME']);
$data = atomized_get_contents("php://input");
$data = file_get_contents("php://input");
}
 
#### Grab the file extension.
@@ -38,7 +30,7 @@
if (!isset($fileExtension) ||
!in_array(strtoupper($fileExtension),
array_map('strtoupper', $ALLOWED_FILE_EXTENSIONS))) {
header('File extension not allowed.', true, 403);
header("HTTP/1.1 500 Internal Server Error", true, 500);
return;
}
@@ -70,7 +62,6 @@
$pathPart = pathinfo($userPath.'.'.$fileExtension);
if (strcasecmp(
realpath($pathPart['dirname']), realpath($STORE_FOLDER)) != 0) {
header('Internal server error.', true, 500);
return;
}
 
@@ -84,7 +75,7 @@
case 'GET':
### If no file has been specified for download then return.
if (!isset($_GET['o']) or empty($_GET['o'])) {
header('File not found.', true, 404);
http_response_code(404);
return;
}
 
@@ -106,7 +97,7 @@
if (!isset($fileExtension) ||
!in_array(strtoupper($fileExtension),
array_map('strtoupper', $ALLOWED_FILE_EXTENSIONS))) {
header('File extension not allowed.', true, 403);
header("HTTP/1.1 500 Internal Server Error", true, 500);
return;
}
@@ -123,7 +114,6 @@
$pathPart = pathinfo($userPath);
if (strcasecmp(
realpath($pathPart['dirname']), realpath($STORE_FOLDER)) != 0) {
header('Internal server error.', true, 500);
return;
}
 
@@ -138,9 +128,10 @@
### Open MIME info database and send the content type.
$finfo = finfo_open(FILEINFO_MIME_TYPE);
if (!$finfo) {
header('Internal server error.', true, 500);
http_response_code(500);
return;
}
header('Content-type: '.finfo_file($finfo, $userPath));
finfo_close($finfo);
break;