dsjz1119 2016-07-17 03:37
浏览 147
已采纳

“警告:in_array()最多需要3个参数,5个”在尝试上传文件时“

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 )
    {
        mkdir($target_dir);
    }

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?

  • 写回答

2条回答 默认 最新

  • douyingzhan5905 2016-07-17 04:11
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了