douyan2470 2017-05-24 09:24
浏览 42
已采纳

在codeigniter中上传多个图像无法正常工作

I want to upload my images array in codeigniter. The names of images are name = standimages[]. This is my controller

$config['upload_path'] = './uploads/individual_stands/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '1024';
$config['max_width'] = '1920';
$config['max_height'] = '1280';
$config['overwrite'] = FALSE;
echo $this->upload_images($config, $_FILES, 'standimages');

And my function

function upload_images($config, $files, $name) {

    if (!file_exists($config['upload_path'])) {
        mkdir($config['upload_path'], 0777, true);
    }

    $filesCount = count($files[$name]['name']);
    for ($i = 0; $i < $filesCount; $i++) {
        $files['userFile']['name'] = $files[$name]['name'][$i];
        $files['userFile']['type'] = $files[$name]['type'][$i];
        $files['userFile']['tmp_name'] = $files[$name]['tmp_name'][$i];
        $files['userFile']['error'] = $files[$name]['error'][$i];
        $files['userFile']['size'] = $files[$name]['size'][$i];

        pre($files);

        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        if ($this->upload->do_upload($files['userFile'])) {
            $fileData = $this->upload->data();
            $uploadData[$i]['file_name'] = $fileData['file_name'];
            $uploadData[$i]['created'] = date("Y-m-d H:i:s");
            $uploadData[$i]['modified'] = date("Y-m-d H:i:s");
        }
    }

    if (!empty($uploadData)) {
        //Insert file information into the database
        $insert = $this->file->insert($uploadData);
        return $statusMsg = $insert ? 'Files uploaded successfully.' : 'Some problem occurred, please try again.';
    }
}

Any idea why my images are not being uploaded?

  • 写回答

4条回答 默认 最新

  • dongyoucha0645 2017-05-24 09:31
    关注

    You must send input name to do_upload function:

     if ($this->upload->do_upload($name) {
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀