0

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!!

1
  • 2
    I think that the filesize is only checked after the upload. So what might be happening is that the file is uploaded, it's too large, so the user sees the error. But the file is there on the server by that point. Commented Oct 3, 2012 at 20:00

2 Answers 2

1

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.');
    }
Sign up to request clarification or add additional context in comments.

6 Comments

Note: this won't prevent the file from being uploaded. The user still has to wait for the whole thing to transfer, and you incur the bandwidth usage involved.
thank you for your reply, how would i check the size of the file and prevent it being uploaded?
@ceejayoz Adding it as a additional info to my answer, permission please :)
@Mr.Alien how do i implement the javascript?
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.