D
D
del9937882015-09-25 20:12:56
PHP
del993788, 2015-09-25 20:12:56

How to check the size of uploaded files before uploading to the server?

Hello. I am zero in php, so I ask you for help. I can only write in Russian what I need)
If the size of all files does not exceed 10 megabytes, then upload the files. Otherwise echo 'not ok';
Here is the file upload code.

$files = $_FILES['fileFF'];
    for($i = 0; $i < count($files['name']); $i++) {
        if(is_uploaded_file($files['tmp_name'][$i])) {
            $file = $files['tmp_name'][$i];
            $filename = $files['name'][$i];
            $filetype = $files['type'][$i];
        }
    }

Can you tell me how to add a size check to this code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Volintsev, 2015-09-26
@del993788

It is possible to read the file without uploading to the server
Here is an example codepen.io/copist/pen/VvmLbZ - select a file in SVG format and it will be displayed immediately. POST or AJAX is not used.
There are special JS libraries that validate files on the browser side: extension, size in bytes, size of images in pixels. I now check that the file containing markup in SVG format is selected.
And also in the PHP and web server settings, you can specify the maximum amount of data to upload to the server. If the size is exceeded, the server simply will not accept files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question