mirror of
https://github.com/Rouji/single_php_filehost.git
synced 2025-04-10 19:08:45 +00:00
check uploaded file's size
This commit is contained in:
parent
af4af0a77a
commit
3232c68e83
10
index.php
10
index.php
@ -95,6 +95,7 @@ function storeFile($name, $tmpFile, $formatted = false)
|
|||||||
global $ID_LENGTH;
|
global $ID_LENGTH;
|
||||||
global $HTTP_PROTO;
|
global $HTTP_PROTO;
|
||||||
global $DOWNLOAD_URL;
|
global $DOWNLOAD_URL;
|
||||||
|
global $MAX_FILESIZE;
|
||||||
|
|
||||||
|
|
||||||
//create folder, if it doesn't exist
|
//create folder, if it doesn't exist
|
||||||
@ -103,6 +104,13 @@ function storeFile($name, $tmpFile, $formatted = false)
|
|||||||
mkdir($STORE_PATH, 0750, true); //TODO: error handling
|
mkdir($STORE_PATH, 0750, true); //TODO: error handling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//check file size
|
||||||
|
if (filesize($tmpFile) > $MAX_FILESIZE * 1024 * 1024)
|
||||||
|
{
|
||||||
|
header("HTTP/1.0 507 Max File Size Exceeded");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$ext = getExtension($name);
|
$ext = getExtension($name);
|
||||||
$id = rndStr($ID_LENGTH);
|
$id = rndStr($ID_LENGTH);
|
||||||
$basename = $id . '.' . $ext;
|
$basename = $id . '.' . $ext;
|
||||||
@ -128,7 +136,7 @@ function storeFile($name, $tmpFile, $formatted = false)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
//TODO: proper error handling
|
//TODO: proper error handling
|
||||||
printf("An error occurred while uploading file.");
|
header("HTTP/1.0 520 Unknown Error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user