PHP

HOW TO RESTRICT UPLOAD FILE SIZE IN PHP

PHP.INI DIRECTIVES

01

file_uploads=On post_max_size=10M upload_max_filesize=10M max_file_uploads=20

HTML FILE UPLOAD FORM

02

<form action="UP.PHP"             enctype="multipart/form-data">   <input type="file" name="up" required/>    <input type="submit" value="Upload"/> </form>

PHP UPLOAD HANDLER

03

MAX ALLOWED SIZE $maxsize = 10000000;   SAVE ONLY IF UPLOADED FILE IS SMALLER if ($_FILES["up"]["size"] <= $maxsize) {   move_uploaded_file($_FILES["up"]   ["tmp_name"], $_FILES["up"]["name"]) } else {   echo "Max allowed is $maxsize bytes";  }