我正在获取空数组,在Codeigniter中上传多个图像时需要图像数组 [英] I am getting empty array, I need array of image while uploading multiple images in Codeigniter

查看:51
本文介绍了我正在获取空数组,在Codeigniter中上传多个图像时需要图像数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码用于获取数组中的文件名。
我正在得到一个空数组的文件。
在这里,我附上同一问题的源代码。
看代码并给我一些解决方案

This code is for getting file name in array. I am getting an empty array of file. Here I am attaching the source code for the same issue. Have look a code and give me some solution

            $images = array();    

            $count = count($_FILES['files']['name']);

            for($i = 0; $i < $count ; $i++)
            {                 

                if(!empty($_FILES['file']['name'][$i]))
                {

                    $tmp = explode(".",$_FILES['files']['name'][$i]);
                    $file_extension = end($tmp); //this is temp variable

                    $imagename = time().".".$file_extension;                                    

                    // Define new $_FILES array - $_FILES['file']
                    $_FILES['file']['name'] = $_FILES['files']['name'][$i];
                    $_FILES['file']['type'] = $_FILES['files']['type'][$i];
                    $_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
                    $_FILES['file']['error'] = $_FILES['files']['error'][$i];
                    $_FILES['file']['size'] = $_FILES['files']['size'][$i];

                    // Set preference
                    $config['upload_path'] = './uploads/'; 
                    $config['allowed_types'] = 'jpg|jpeg|png|gif';   // this is allowed file type                 
                    $config['file_name'] = $imagename;

                    //Load upload library
                    $this->load->library('upload',$config);                                                     
                    if($this->upload->do_upload('file')){
                        // Get data about the file
                        $uploadData = $this->upload->data();
                        $filename = $uploadData['file_name'];

                        // Initialize array
                        array_push($images, $filename);
                    }                    
                }
            }
            echo "<pre>";print_r($images);die;

在这里我还要附加表单代码

Also here I am attaching form code

 <?php $attributes = array(
 "class"                 => "form-horizontal m-t-20",
 "method"                => "post",
 "novalidate"            => "",
 "enctype"               => "multipart/form-data"
 );
 echo form_open('admin/user/adduser', $attributes); ?>

This code for file input
<label for="file">Profile Images*</label>
<input type="file" name="files[]" id="file" multiple required placeholder="Profile Images" class="form-control">


推荐答案

替换行

if(!empty($_FILES['file']['name'][$i]))

if(!empty($_FILES['files']['name'][$i]))

这篇关于我正在获取空数组,在Codeigniter中上传多个图像时需要图像数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆