Browse Source

Improved large file size error message.

pull/40/head
Paul Merrill 12 years ago
parent
commit
455f0c2602
  1. 4
      inc/config.php
  2. 2
      inc/display.php
  3. 16
      inc/functions.php
  4. 9
      post.php

4
inc/config.php

@ -40,7 +40,7 @@
define('ERROR_NOMOVE', 'The server failed to handle your upload.');
define('ERROR_FILEEXT', 'Unsupported image format.');
define('ERR_INVALIDIMG','Invalid image.');
define('ERR_FILSIZE', 'The file was too large.');
define('ERR_FILESIZE', 'Maximum file size: %maxsz% bytes<br>Your file\'s size: %filesz% bytes');
define('ERR_MAXSIZE', 'The file was too big.');
// For resizing, max values
@ -48,7 +48,7 @@
define('THUMB_HEIGHT', 200);
// Maximum image upload size in bytes
define('MAX_FILESIZE', 1048576); // 10MB
define('MAX_FILESIZE', 10*1024*1024); // 10MB
// Maximum image dimensions
define('MAX_WIDTH', 10000);
define('MAX_HEIGHT', MAX_WIDTH);

2
inc/display.php

@ -15,7 +15,7 @@
}
function error($message) {
die(Element('page.html', Array('index' => ROOT, 'title'=>'Error', 'subtitle'=>'An error has occured.', 'body'=>"<h1>$message</h1><p style=\"text-align:center;\"><a href=\"" . ROOT . FILE_INDEX . "\">Go back</a>.</p>")));
die(Element('page.html', Array('index' => ROOT, 'title'=>'Error', 'subtitle'=>'An error has occured.', 'body'=>"<center><h2>$message</h2></center><p style=\"text-align:center;\"><a href=\"" . ROOT . FILE_INDEX . "\">Go back</a>.</p>")));
}
class Post {

16
inc/functions.php

@ -1,4 +1,18 @@
<?php
function sprintf3($str, $vars, $delim = '%') {
$replaces = array();
foreach($vars as $k => $v) {
$replaces[$delim . $k . $delim] = $v;
}
return str_replace(array_keys($replaces),
array_values($replaces), $str);
}
function commaize($n) {
$n = strval($n);
return (intval($n) < 1000) ? $n : commaize(substr($n, 0, -3)) . ',' . substr($n, -3);
}
function sql_open() {
global $sql;
$sql = @mysql_connect(MY_SERVER, MY_USER, MY_PASSWORD) or error('Database error.');
@ -502,4 +516,4 @@
function int_to_word($n) {
return chr($n & 255).chr(($n >> 8) & 255);
}
?>
?>

9
post.php

@ -74,8 +74,13 @@
$post['filename'] = $_FILES['file']['name'];
$post['has_file'] = $OP || !empty($_FILES['file']['tmp_name']);
if($post['has_file'] && $_FILES['file']['size'] > MAX_FILESIZE)
error(ERR_FILSIZE);
if($post['has_file']) {
$size = $_FILES['file']['size'];
if($size > MAX_FILESIZE)
error(sprintf3(ERR_FILESIZE, array(
'filesz'=>commaize($size),
'maxsz'=>commaize(MAX_FILESIZE))));
}
$trip = generate_tripcode($post['name']);
$post['name'] = $trip[0];

Loading…
Cancel
Save