Maximum Upload
This commit is contained in:
23
upload.php
23
upload.php
@ -4,13 +4,16 @@ error_reporting(E_ALL);
|
||||
ini_set('display_errors', TRUE);
|
||||
ini_set('display_startup_errors', TRUE);
|
||||
|
||||
include 'fonction.php';
|
||||
|
||||
$max_size = convertToBytes('2GB');
|
||||
|
||||
$root = $_SERVER["DOCUMENT_ROOT"];
|
||||
|
||||
$target_dir = "$root/uploads/";
|
||||
|
||||
if(! isset($_FILES["file"])) {
|
||||
header("HTTP/1.1 400 No file Upload");
|
||||
//trigger_error("No file Upload",E_USER_ERROR);
|
||||
exit();
|
||||
}
|
||||
|
||||
@ -18,9 +21,15 @@ $file = $_FILES["file"];
|
||||
|
||||
$name = basename($file["name"]);
|
||||
|
||||
$size = basename($file["size"]);
|
||||
|
||||
if ((folderSize($target_dir) + $size) > $max_size) {
|
||||
header("HTTP/1.1 400 " . $name . " file too large");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (! extension_loaded('mbstring')) {
|
||||
header("HTTP/1.1 400 Bad encode");
|
||||
header("HTTP/1.1 500 php module missing");
|
||||
exit();
|
||||
}
|
||||
|
||||
@ -29,9 +38,6 @@ if(! mb_check_encoding($name)) {
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
$size = basename($file["size"]);
|
||||
|
||||
$target_file = $target_dir.$name;
|
||||
|
||||
// Check if file already exists
|
||||
@ -48,11 +54,4 @@ else {
|
||||
}
|
||||
}
|
||||
|
||||
function formatBytes($size, $precision = 2)
|
||||
{
|
||||
$base = log($size, 1024);
|
||||
$suffixes = array('', 'KiB', 'MiB', 'GiB', 'TiB');
|
||||
|
||||
return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user