How to handle multiple file upload using PHP

后端 未结 5 728
-上瘾入骨i
-上瘾入骨i 2020-11-29 07:57

I want to upload files using PHP but the problem is that I don\'t know how many files I will upload.

My question is how can I upload files if I use file[]

5条回答
  •  余生分开走
    2020-11-29 08:31

    Try this:

    if(isset($_FILES['image_file'])) {
        $file = $_FILES['image_file'];
        for($i = 0; $i < count($file['name']); $i++){
            $image = array(
                'name' => $file['name'][$i],
                'type' => $file['type'][$i],
                'size' => $file['size'][$i],
                'tmp_name' => $file['tmp_name'][$i],
                'error' => $file['error'][$i]
            );
    // Here is your code to handle one file
    }
    

    In your code, just use '$image' instead of '$_FILES' ...

提交回复
热议问题