4

I have an page with php code to upload user's picture for every account.Size of their image file must less than 100 kb size.

I want prevent uploading file more than 100 KB on server from users(in registering new user in image profile field) and during uploading(Not after uploading the entire file and just during uploading it), if the upload volume exceeds 100 KB, stop uploading progress and display warning for user by PHP(Preferred) OR any other script language for server-side code.

I searched by stackoverflow and google I didn't find any help or source about that.

Please help me

harix
  • 247
  • 2
  • 13

1 Answers1

1

The most obvious option is a few lines of Javascript added to your HTML that will be your first line of defense:

var uploadField = document.getElementById("file");

uploadField.onchange = function() {
    if(this.files[0].size > 100000){
       alert("File is too big!");
       this.value = "";
    };
};

If you then also ensure that your form can only be submitted via javascript like this:

http://javascript-coder.com/javascript-form/javascript-form-submit.phtml

That way, the user can't just turn off Javascript and upload any size they want.

It might be possible to do this by using a chunk process to upload your file in chunks instead of one big file, but I dont think I've tried to restrict filesize that way before...

R. Smith
  • 464
  • 4
  • 9