doukong9982 2016-10-18 10:36
浏览 26
已采纳

如何在循环中获取文件名加密文件上传codeigniter

for ($img=0;$img<=5;$img++)
{
    if (!empty($_FILES['picture_add_'.$img]))
    {
        if ($this->upload->do_upload('picture_add_'.$img))
        {
            $uploaded = $this->upload->data();
            $data_picture_add = array(
                                    'filename'  => $uploaded['file_name'],
                                    'id'        => $last_id
                                    );
            $this->db->insert('db_picture_individual', $data_picture_add);
        }
    }
}

if I input 2 file picture or more, I just get one filename encrypted.

How to get all filename encrypted ?

this is the view :

<input name="picture_add_1" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_add_2" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_add_3" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_add_4" class="form-control" style="padding-top: 0;" type="file">
<input name="picture_add_5" class="form-control" style="padding-top: 0;" type="file">
  • 写回答

1条回答 默认 最新

  • dtn51137 2016-10-18 12:01
    关注

    try to use config inside your loop statement.

            for ($i = 1; $i <= count($_FILES); $i++) {
               $config = array();
               $config['upload_path'] = './media/project_files';
               $config['allowed_types'] = '*';
               $config['max_size'] = '51200';
               $config['max_width'] = '5000';
               $config['max_height'] = '5000';
               $config['remove_spaces'] = TRUE;
               $config['encrypt_name'] = TRUE;
    
                $ups = $this->upload->do_upload("upload_file$i");
                $imgName[$i] = $this->upload->data();
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名