Answer the question
In order to leave comments, you need to log in
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];
}
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question