PHP - prohibit uploading a file more than 100 KB during uploadin file not after downloading the whole file

I have a page with php code to upload a user image for each account. Image file size must be less than 100 kb.

I want not to download the file more than 100 KB on the server from users (when registering a new user in the image profile field) and when downloading (not after downloading the whole file and only when downloading it) if the download volume exceeds 100 KB, stop downloading progress and display a warning to the user for PHP ( Preferred ) or any other script language for the server code .

I searched for stackoverflow and google. I did not find any help or source about this.

Please help me

+4
source share
1 answer

The most obvious option is a few lines of Javascript added to your HTML, which 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 also make sure that your form can only be submitted via javascript:

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

Thus, the user cannot simply turn off Javascript and load any desired size.

Perhaps it will be possible using the chunk process to load your file into chunks instead of one large file, but I don't think I tried to limit the file size this way before ...

+1
source

Source: https://habr.com/ru/post/1690741/


All Articles