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 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程