【问题标题】:Codeigniter 3 - can I get image upload's url from 3 images?Codeigniter 3 - 我可以从 3 张图片中获取图片上传的网址吗?
【发布时间】:2016-11-18 07:43:41
【问题描述】:

您好,我使用 Codeigniter 一次上传 3 张图片,我可以成功上传,但我不知道如何从 3 张图片中获取 url(我只能从最后一张图片中获取 url。)(我想插入 3图片的 url 到数据库)

这是我的代码

控制器

 public function add_event()
   {

 $config['upload_path']          = 'images/location';
    $config['allowed_types']        = 'gif|jpg|png';
    $config['max_size']             = 2048; 
    $config['max_width']            = 2000;
    $config['max_height']           = 1500;

$this->load->library('upload', $config);

 $this->upload->do_upload('userfile'); 
 $this->upload->do_upload('userfile2');
 $this->upload->do_upload('userfile3');

$data_upl = array('upload_data' => $this->upload->data());

$this->load->view('admin/success', $data_upl);
 }

我的上传表单视图

        <?php echo form_open_multipart('admin/add_event') ?>

            pic1
            <input type="file" name="userfile" size="20" />

            pic2
            <input type="file" name="userfile2" size="20" />


            pic3
            <input type="file" name="userfile3" size="20" />

            <input type="submit" value="upload"/>
         <?php echo form_close(); ?>

我的成功页面视图(我想在这个页面中回显3张图片的url!但我只得到最后一张图片的1个url)(实际上我想插入到数据库中)

<h1>Successfully Add</h1>

<ul>
<li><?php echo $upload_data['full_path'];?></li>
</ul>

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    我假设 $this->upload->data() 获取上次上传文件的信息,不是吗?你能做一个 print_r($upload_data) 吗? 或者你能试试这样的吗?

    $upload_data=array();
    $this->upload->do_upload('userfile'); 
    $upload_data['1']= $this->upload->data());
     $this->upload->do_upload('userfile2');
    $upload_data['2']= $this->upload->data());
     $this->upload->do_upload('userfile3');
    $upload_data['3']= $this->upload->data());
    

    【讨论】:

      【解决方案2】:

      $this->upload->data() 是最后上传的数据,请尝试

      ........
      
      $alldata=array();
      $this->upload->do_upload('userfile'); 
      $alldata[]=$this->upload->data();
      
      $this->upload->do_upload('userfile2');
      $alldata[]=$this->upload->data();
      
      $this->upload->do_upload('userfile3');
      $alldata[]=$this->upload->data();
      
      $data_upl = array('upload_data' => $alldata);
      

      .......

      <h1>Successfully Add</h1>
      
      <ul>
      <li><?php print_r($upload_data);?></li>
      </ul>
      

      【讨论】:

        【解决方案3】:

        在这个阶段,您正在上传 3 个文件,但只获取最后插入文件的数据。

        $this->upload->do_upload('userfile'); 
        $this->upload->do_upload('userfile2');
        $this->upload->do_upload('userfile3');
        $data_upl = array('upload_data' => $this->upload->data());
        

        您应该获取每个文件的数据并推送到数组。喜欢

        $data = array();
        $data['upload_data'] = array();
        $this->upload->do_upload('userfile'); 
        $data['upload_data'][0] = $this->upload->data();
        $this->upload->do_upload('userfile2');
        $data['upload_data'][1] = $this->upload->data();
        $this->upload->do_upload('userfile3');
        $data['upload_data'][2] = $this->upload->data();
        

        【讨论】:

          猜你喜欢
          • 2013-07-11
          • 2016-11-22
          • 2012-09-19
          • 2020-12-11
          • 1970-01-01
          • 1970-01-01
          • 2023-03-06
          • 1970-01-01
          • 2017-07-31
          相关资源
          最近更新 更多