连接上传的图像文件名
我使用下面的代码上传多个图像,获取图像文件名,用“,”连接并返回值,以便可以使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只能按照代码显示的方式获取最后一个文件的文件名(如果有效的话)。要保存与 a 连接的图像名称,您可以执行以下操作。
或者
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.
or
我认为你需要对此代码进行一些更改..
i think you need to do some change in this code..
更改图像名称上的符号以构建一个数组
,然后将内爆移到循环之外
change the notation on image name to build up an array
then move your implode to outside of the loop