Added a maximum filesize for image uploads

This commit is contained in:
Savetheinternet 2010-11-03 19:44:24 +11:00
parent 0b50ef702f
commit 690f206a63
2 changed files with 7 additions and 0 deletions

View File

@ -40,11 +40,15 @@
define('ERROR_NOMOVE', 'The server failed to handle your upload.'); define('ERROR_NOMOVE', 'The server failed to handle your upload.');
define('ERROR_FILEEXT', 'Unsupported image format.'); define('ERROR_FILEEXT', 'Unsupported image format.');
define('ERR_INVALIDIMG','Invalid image.'); define('ERR_INVALIDIMG','Invalid image.');
define('ERR_FILSIZE','The file was too large.');
// For resizing, max values // For resizing, max values
define('THUMB_WIDTH', 200); define('THUMB_WIDTH', 200);
define('THUMB_HEIGHT', 200); define('THUMB_HEIGHT', 200);
// Maximum image upload size in bytes
define('MAX_FILESIZE', 1048576); // 10MB
define('DIR_IMG', 'src/'); define('DIR_IMG', 'src/');
define('DIR_THUMB', 'thumb/'); define('DIR_THUMB', 'thumb/');
define('DIR_RES', 'res/'); define('DIR_RES', 'res/');

View File

@ -74,6 +74,9 @@
$post['filename'] = $_FILES['file']['name']; $post['filename'] = $_FILES['file']['name'];
$post['has_file'] = $OP || !empty($_FILES['file']['tmp_name']); $post['has_file'] = $OP || !empty($_FILES['file']['tmp_name']);
if($post['has_file'] && $_FILES['file']['size'] > MAX_FILESIZE)
error(ERR_FILSIZE);
$trip = generate_tripcode($post['name']); $trip = generate_tripcode($post['name']);
$post['name'] = utf8tohtml($trip[0]); $post['name'] = utf8tohtml($trip[0]);
$post['trip'] = (isset($trip[1])?$trip[1]:''); $post['trip'] = (isset($trip[1])?$trip[1]:'');