Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP filter_input_array for $_FILES?

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
like image 632
ehime Avatar asked Dec 27 '22 05:12

ehime


2 Answers

try using filter_var_array instead to filter $_FILES .

filter_var_array($_FILES, $filters);
like image 67
Mouna Cheikhna Avatar answered Jan 10 '23 02:01

Mouna Cheikhna


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?

like image 23
drew010 Avatar answered Jan 10 '23 02:01

drew010