4

Is there a way to filter_input_array for $_FILES?

I tried

$ar = filter_input_array(INPUT_FILES, $args);

but it doesn't seem to be the same syntax as $_POST:

$pd = filter_input_array(INPUT_POST, $args);

And after quick check of the Constants List shows that it isn't an installed definition for filter_input_array.

So, should I define it some other way? DEFINE('INPUT_FILES' $_FILES); likes to throw errors in filter_var_array like

Warning: Constants may only evaluate to scalar values in .... Line 2
Warning: filter_input_array() expects parameter 1 to be long, string given .... Line 37
1
  • what you want to filter and what for? Commented Feb 28, 2012 at 21:36

4 Answers 4

5

try using filter_var_array instead to filter $_FILES .

filter_var_array($_FILES, $filters);
Sign up to request clarification or add additional context in comments.

Comments

4

You can't use filter_input_array on $_FILES. None of the filter types are suitable for file uploads.

From the PHP manual on filter_input_array:

mixed filter_input_array ( int $type [, mixed $definition ] )

type

One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.

How/what exactly did you want to filter from the files?

3 Comments

that's not true, there's quite a few helpful filters imho, like FILTER_SANITIZE_STRING for naming conventions, FILTER_VALIDATE_INT in conjunction with option min/max for preventing large files, and importantly FILTER_REQUIRE_ARRAY for making sure that uploads are multipart
Good point about the INT filter. PHP can and will already deal with maximum upload size, but not minimum. As far as the filename goes, I would never trust the name of the file from the user; in this case SANITIZE_STRING would be helpful, or not use the supplied name at all. When uploading files from the browser, if the enctype is NOT multipart, then the upload will not work.
I'm just trying to do a bit of future site here with my posts so I can keep the validation in my class' a bit lighter. Yeah I went through the docs and there are quite a few helpful things I found.
1

As per php manual, There is no INPUT_FILES for filter_input_array. I am not sure if a DEFINE would produce the answer you would want.

Take a look at the php manual for filter_input_array

Also check out this post which may be of some help to you. PHP can (should) I array_map filter_var to $_POST

Edit: You will not be able to define a new type for this function.

Comments

0

Please see: filter_input_array

You will see that INPUT_FILES is not a valid constant to be used.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.