block upload greater than 2mb with PHP

Asked

Viewed 328 times

2

Guys like me block an upload larger than 2mb?

I’m capturing the file like this:

$imagem = $_FILES["imagem"];

1 answer

5


Each $_FILES key/file pussui a key size, that by default comes measured in bytes. We can convert like this

for 2mb:

if($_FILES['imagem']['size'] > 2097152) {
    echo 'não é permitido';
}

To 2gb:

if($_FILES['imagem']['size'] > 2147483648) {
    echo 'não é permitido';
}

Note that for 2gb is a large file, you must have the right settings in the server, php.ini:

post_max_size = 2048M
upload_max_filesize = 2048M

Browser other questions tagged

You are not signed in. Login or sign up in order to post.