热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

php–使用CodeIgniter上传多个图像

我是在我的项目中使用代码点火器的新用户,我在上传多个文件时面临一个问题,但最后一个只插入到所有图像三个图像字段.我的控制器是:functionprodu

我是在我的项目中使用代码点火器的新用户,我在上传多个文件时面临一个问题,但最后一个只插入到所有图像三个图像字段.

我的控制器是:

function products()
{
date_default_timezone_set("Asia/Kolkata");
$config['upload_path'] = './resources/images/products/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->do_upload('userfile');
$data = array('prod_image' => $this->upload->data(),
'prod_image1' => $this->upload->data(),
'prod_image2' => $this->upload->data());
$product_image=$data['prod_image']['file_name'];
$product_image1=$data['prod_image1']['file_name'];
$product_image2=$data['prod_image2']['file_name'];
$data = array('name' => $this->input->post('pd_name'),'prod_image' => $product_image,'prod_image1' => $product_image1,'prod_image2' => $product_image2,'created_time' => date('Y-m-d H:i:s'));
// insert form data into database
$result_set= $this->tbl_products_model->insertUser($data);
}

我的观点部分是:


//1
//2
//3

请帮助如何插入3张图片.

我的datad基地就像

===========================================
id|name|prod_image|prod_image1|prod_image2|
===========================================
1|ard| | | |
============================================

解决方法:

Html:


PHP:

public function products()
{
$this->load->library('upload');
$dataInfo = array();
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
$dataInfo[] = $this->upload->data();
}
$data = array(
'name' => $this->input->post('pd_name'),
'prod_image' => $dataInfo[0]['file_name'],
'prod_image1' => $dataInfo[1]['file_name'],
'prod_image2' => $dataInfo[2]['file_name'],
'created_time' => date('Y-m-d H:i:s')
);
$result_set = $this->tbl_products_model->insertUser($data);
}
private function set_upload_options()
{
//upload an image options
$cOnfig= array();
$config['upload_path'] = './resources/images/products/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
return $config;
}
?>


推荐阅读
author-avatar
情感顾问世界
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有