neeko
neeko

Reputation: 2000

Restrict image upload file size

currently i have php validation as follows

if ($_FILES["file"]["size"] > 5120) 
{
$_SESSION['error'] = 'Upload FAILED, file is too large !';
header("Location: upload.php");
exit;
}

But this does not seem to stop any large files being uploaded! any help much appreciated!!

Upvotes: 0

Views: 1966

Answers (2)

Mr. Alien
Mr. Alien

Reputation: 157284

Use this to restrict the upload file size :

$max_size = /* whatever */; //File Size in Bytes

if(filesize($_FILES['userfile']['tmp_name']) > $max_size) {
      die('The file you uploaded is too large.');
    }

Upvotes: 1

Philip Whitehouse
Philip Whitehouse

Reputation: 4157

Use upload_max_filesize

Entry can be set in php.ini, .htaccess, httpd.conf or .user.ini

http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize

Upvotes: 0

Related Questions