Once we load a file to the server we can process it.
First let's restrict the size of files that can be uploaded.
Before we check the size of the loaded file once it's on the server.
P HP has a couple of settings that restricts the maximum size of data that can be sent to the server.
If we add the P HP infeld function to the top of a script like this.
When we view that page in a browser we're shown all the data about the server.
There are two settings we need to look at.
Post max size is the size limit for a farm submitted using the post method.
This includes the contents of all input controls including text inputs file inputs and so on in a single
farm upload Max file size is the size of the MIT for single files in a file input control.
We're interested in the value in the first column and here for example.
They're both set to 128 megabytes.
If you need to change these.
The best place is in the p h product.
Any file itself and that is located here on the server.
This will be different depending on your system.
Bear in mind that these limits are for the entire server so you might not want to change them.
If you are running more than one site.
You probably have access to this file on your local machine.
However on a life server you might not.
There are a couple of options for changing this setting on a life server.
If you don't have access to change P HP does any.
Firstly you can do it in an ace to access file by putting p p value are P P Flag for the by the name
of the setting and its new value.
The second is to call the any set function from your P HP code again passing in the name of the setting
and the desired value.
I don't recommend this second method though.
I asked changing server settings in p s p.
Code can be difficult to debug when moving between servers.
For example let's add an HD access file to the roots of the site.
And in here put the p h p value directive to change the upload Max file size setting to 2 megabytes
then before we try this in our upload script let's remove the P 8 p.
Info line like that.
So if I select a file that's greater than 2 megabytes and submit the form we get a message saying an
error occurred and the error code is one.
The error code being one corresponds to this constant.
The uploaded file exceeds the value we just set in the P P.
Any settings.
So we can add a case for this error in the switch statement and throw an exception with a custom message.
So now when I upload a file that's too large we get that message.
Now earlier on we looked at two settings that restrict file upload sizes.
We just changed the upload Max file size in an 80 access file to two megabytes and we cart the error
that occurs if we upload a file.
Bigger than this value.
Watch what happens there when I upload a file that's bigger than the post max size value of 128 megabytes.
If I select a very large file and submit the form we get a warning error an empty array which is the
files away we're dumping out and an error saying there's an undefined index.
Unfortunately we can't trap this error in our code in the same way as the other.
Any setting.
In fact we can't trap this error at all.
This error is displayed because this setting display start-up errors is enabled.
However this isn't normally disabled in production environments.
Online servers.
So all we have to worry about is the files array being empty.
We can switch this setting off in the h.t. Access file like that.
Then all we need to worry about is the files of a being empty.
So before we start to use the array let's check it's not empty and if it is throw out an exception.
So now if I try to upload a file that's bigger than the post max size value.
We get the invalid upload message like that.
I'll leave this h to access file here so that it's available in the downloadable code but in the rest
of the lectures.
In this section I'll remove it as I prefer to rely on the settings in the server's configuration file
rather than setting them in here.