PHP - Upload multiple images

前端 未结 2 1001
盖世英雄少女心
盖世英雄少女心 2020-12-01 20:43

I need to upload multiple images via form. I thought that I will do it with no problem, but I have one.

When I try to do foreach and get image by image it is not act

相关标签:
2条回答
  • 2020-12-01 21:02

    You are basically asking of how to rebuild the $_FILES array to access subitems of them as one array.

    $index = 0;
    $field = 'fileImage';
    $keys = array_keys($_FILES[$field]);
    $file = array();
    foreach($keys as $key)
    {
        $file[$key] = $_FILES[$field][$key][$index];
    }
    print_r($file);
    

    change $index to the value you need to pick a specific file.

    0 讨论(0)
  • 2020-12-01 21:07

    that array is formed in another way

    it's something line this:

    array ( 
        'name' => array (
           [0] => 'yourimagename',
           [1] => 'yourimagename2',
           ....
        ),
        'tmp_file' => array (
        ....
    

    that shoud do it :

    foreach ($_FILES['fileImage']['name'] as $file)
        {
            print_r($file);
            die(); // I want it to print first image content and then die to test this out...
            //imgUpload($file) - I already have working function that uploads one image
        }
    
    0 讨论(0)
提交回复
热议问题