Although you can use a similar technique to reject files that are too large (by checking the $uploadedfile_size variable), this is generally not a good idea. Before getting this variable, this file has been uploaded and saved in the temp directory. This may be a problem for you if you try to reject a file upload due to disk capacity or bandwidth reasons, and the large files are actually uploaded anyway (even though they are immediately deleted).
A better way is that you can tell PHP in advance the upper limit of the file size you want to accept.
There are two methods.
The first is to adjust the upload_max_filesize setting in your php.ini file. The default value is 2mb, so if you want to accept larger files, you need to change this value immediately.
The second method is to include an implicit input field in your form, its name is max_file_size, in which you can define the largest file size you can accept. For security reasons, this value cannot exceed the upload_max_filesize setting in your php.ini file, but it provides a way to define the upper limit of upload file size in different pages. For example, the following form only allows us to upload files up to 1k bytes (1024 bytes):