连接上传的图像文件名

发布于 2024-12-10 15:41:18 字数 769 浏览 2 评论 0原文

我使用下面的代码上传多个图像,获取图像文件名,用“,”连接并返回值,以便可以使用 CodeIgniter 将其插入数据库。

我遇到的问题是无法使用 implode() 连接文件名。

有人可以告诉我我做错了什么吗?

function upload(){
      $config['upload_path'] = './uploadsim/'; 
      $config['allowed_types'] = 'gif|jpg|jpeg';
      $config['max_size']  = '0';
      $config['max_width']  = '0';
      $config['max_height']  = '0';
      $this->load->library('upload', $config);

  for($i = 1; $i < 6; $i++) {

        $upload = $this->upload->do_upload('image'.$i);

        if($upload === FALSE) continue;

        $images = array('upload_data'=>$this->upload->data());
        $imagename= $images['upload_data']['file_name'];
        $impl=  implode(",", $imagename);


  }
     return $impl;

}  

im using the below code to upload multiple images, take the image file name, concatenate with “,” and return the value so it can be used to insert into the database using CodeIgniter.

The problem that im having is im unable to concatenate the file names using implode().

Can someone please tell me what am i doing wrong?

function upload(){
      $config['upload_path'] = './uploadsim/'; 
      $config['allowed_types'] = 'gif|jpg|jpeg';
      $config['max_size']  = '0';
      $config['max_width']  = '0';
      $config['max_height']  = '0';
      $this->load->library('upload', $config);

  for($i = 1; $i < 6; $i++) {

        $upload = $this->upload->do_upload('image'.$i);

        if($upload === FALSE) continue;

        $images = array('upload_data'=>$this->upload->data());
        $imagename= $images['upload_data']['file_name'];
        $impl=  implode(",", $imagename);


  }
     return $impl;

}  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘寄 2024-12-17 15:41:19

您只能按照代码显示的方式获取最后一个文件的文件名(如果有效的话)。要保存与 a 连接的图像名称,您可以执行以下操作。

$imagename = ""; #before the for loop
$imagename .= ',' . $images['upload_data']['file_name']; #in the for loop

或者

$imagename[($i-1)] = $images['upload_data']['file_name']; # in the for loop
$impl = imploade(",",$imagename; # outside the for loop

You will only get the filename of the last file the way the code is showing (if works at all). To samve the image name concated with a , you can do a couple of things.

$imagename = ""; #before the for loop
$imagename .= ',' . $images['upload_data']['file_name']; #in the for loop

or

$imagename[($i-1)] = $images['upload_data']['file_name']; # in the for loop
$impl = imploade(",",$imagename; # outside the for loop
你在看孤独的风景 2024-12-17 15:41:19

我认为你需要对此代码进行一些更改..

for($i = 1; $i < 6; $i++) {

        $upload = $this->upload->do_upload('image'.$i);

        if($upload === FALSE) continue;

        $images = array('upload_data'=>$this->upload->data());
        $imagename[] = $images['upload_data']['file_name'];


  }
$impl =  implode(",", $imagename);

return $impl;

i think you need to do some change in this code..

for($i = 1; $i < 6; $i++) {

        $upload = $this->upload->do_upload('image'.$i);

        if($upload === FALSE) continue;

        $images = array('upload_data'=>$this->upload->data());
        $imagename[] = $images['upload_data']['file_name'];


  }
$impl =  implode(",", $imagename);

return $impl;
似梦非梦 2024-12-17 15:41:18

更改图像名称上的符号以构建一个数组

$imagename[] = $images['upload_data']['file_name'];

,然后将内爆移到循环之外

return implode(",", $imagename);

change the notation on image name to build up an array

$imagename[] = $images['upload_data']['file_name'];

then move your implode to outside of the loop

return implode(",", $imagename);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文