Hello Reader's if you are developing the website and you want to restrict file upload to max of 4 then you can use the code as below:-
The logic for this condition is you just have to return false is count of array is more than 4. Let's see how is it done:-
On the HTML
<input type="file" multiple="multiple" name="something[]" />
Now make the validation like this:-
if(empty($_FILES['something']['name'][0]))
{
//checking whether a single file uploaded or not
//if enters here means no file uploaded
//so if you want you may put a check/validation here to make file
//upload a must in your website
}
if(isset($_FILES['something']['name'][4]))
{
//checking whether 5 files uploaded or not
//so here you can put a check/validation to restrict user from
//uploading more than 4 files
}
0 Comment(s)