Underdog Underdog - 1 year ago 116
MySQL Question

"Warning: in_array() expects at most 3 parameters, 5 given" when try upload file

I tried using some file input in a form for uploading several different file types and when clicking on the submit button then file multiple files are stored in a mysql table .
the problem is when clicking the sumbit it will display an error: "Warning : in_array ( ) expects at most 3 parameters , 5 given in....". when I use one input file , the file was successfully uploaded to the server folder .
and this is the code I used :

$dir = $name;
$target_dir = "my-file/$dir/";
if( is_dir($target_dir) === false )

if(isset($_POST["submit"])) {
$formatfilea = array("pdf");
$formatfileb = array("pdf");
$formatfilec = array("pdf");
$formatfiled = array("jpg, jpeg");

$filea = $_FILES['filea']['name'];
$fileb = $_FILES['fileb']['name'];
$filec = $_FILES['filec']['name'];
$filed = $_FILES['filed']['name'];

$xa = explode('.', $filea);
$xb = explode('.', $fileb);
$xc = explode('.', $filec);
$xd = explode('.', $filed);

$existencea = strtolower(end($xa));
$existenceb = strtolower(end($xb));
$existencec = strtolower(end($xc));
$existenced = strtolower(end($xd));

$sizea = $_FILES['filea']['size'];
$sizeb = $_FILES['fileb']['size'];
$sizec = $_FILES['filec']['size'];
$sized = $_FILES['filed']['size'];

$file_tmp_a = $_FILES['filea']['tmp_name'];
$file_tmp_b = $_FILES['fileb']['tmp_name'];
$file_tmp_c = $_FILES['filec']['tmp_name'];
$file_tmp_d = $_FILES['filed']['tmp_name'];

if(in_array($existencea, $formatfilea && $existenceb, $formatfileb && $existencec, $formatfilec && $existenced, $formatfiled) === true){

if($sizea < 1044070 && $sizeb < 1044070 && $sizec < 1044070 && $sized < 1044070){
move_uploaded_file($file_tmp_a, $target_dir.$filea);
move_uploaded_file($file_tmp_b, $target_dir.$fileb);
move_uploaded_file($file_tmp_c, $target_dir.$filec);
move_uploaded_file($file_tmp_d, $target_dir.$filed);
} else {


// attempt insert query execution

$sql = "INSERT INTO test (filea, fileb, filec, filed) VALUES ('$filea', '$fileb', '$filec', '$filed')";

is there who can help me provide a solution? What causes this error? and why I uploaded file is not found on the file server?

Answer Source

You should refer to the syntax of in_array(). It accepts, at least two parameters.

 in_array(param_1, param_2, param_3);

First one is the one you want to find.

Second one is the array.

Third parameter is optional. You can set it to true if you want to use strict checking so that it checks the type as well.

You just need to write your if statement this way:

if (in_array($existencea, $formatfilea, true) && in_array($existenceb, $formatfileb, true) && in_array($existencec, $formatfilec, true) && in_array($existenced, $formatfiled, true)) {

Note: Setting the third parameter to true will strengthen your code.

Refer to second example: in_array() strict checking

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download