dongpu1331 2019-01-18 12:51
浏览 42
已采纳

Codeigniter获取多个文件的图像名称

I have some code that i am using to upload multiple images i a form. I am uploading and renaming the images like this

//Obtain Picture

        $config['upload_path']          = './uploads/';
        $config['allowed_types']        = 'gif|jpg|png|pdf';
        $config['max_size']             = 5000;
        $config['max_width']            = 2000;
        $config['max_height']           = 2000;
        $rand_name = 'vehicles'.rand(321,8999).'_'.time();
        $config['file_name'] = $rand_name;
        $this->load->library('upload', $config);
        $this->upload->do_upload('logbook');
        $this->upload->do_upload('inrep');
        $this->upload->do_upload('insurance');
        $this->upload->do_upload('vp');
        $data = array('upload_data' => $this->upload->data());

the form names for the multiple uploads which are unrelated are as follows logbook,inrep,insurance and vp

The code above uploads the files and renames them but i would like to obtain the new names of the files given the form name of the fields.

Right now, the files are uploaded and renamed but i cant they are from which field name.

  • 写回答

1条回答 默认 最新

  • douhuang1852 2019-01-18 13:10
    关注

    You can get new file name using

    $this->upload->data();
    

    This will return details of uploaded files. So you can do it like

    $config['upload_path']          = './uploads/';
    $config['allowed_types']        = 'gif|jpg|png|pdf';
    $config['max_size']             = 5000;
    $config['max_width']            = 2000;
    $config['max_height']           = 2000;
    $rand_name = 'vehicles'.rand(321,8999).'_'.time();
    $config['file_name'] = $rand_name;
    $this->load->library('upload', $config);
    
    $this->upload->do_upload('logbook');
    $logbook = $this->upload->data();
    $logbook_new_filename = $logbook['file_name'];
    
    $this->upload->do_upload('inrep');
    $inrep = $this->upload->data();
    $inrep_new_filename = $inrep['file_name'];
    
    $this->upload->do_upload('insurance');
    $insurance= $this->upload->data();
    $insurance_new_filename = $insurance['file_name'];
    
    $this->upload->do_upload('vp');
    $vp= $this->upload->data();
    $vp_new_filename = $vp['file_name'];
    

    I haven't tested it. But I use like this to get uploaded filename.Hope it will help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 SAP HANA SQL Script 。SUM OVER 怎么加where
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题
  • ¥60 为什么使用python对地震数据进行umap降维后,数据成图会出现不连续的现象
  • ¥100 房产抖音小程序苹果搜不到安卓可以付费悬赏
  • ¥15 STM32串口接收问题
  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接
  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败