更新时间:2023-01-15 12:43:45
查看此代码可能有助于了解如何处理多个图像
Have a look upon this code may this help in understanding you how to handle multiple images
#####################
# Uploading multiple#
# Images #
#####################
$files = $_FILES;
$count = count($_FILES['uploadfile']['name']);
for($i=0; $i<$count; $i++)
{
$_FILES['uploadfile']['name']= $files['uploadfile']['name'][$i];
$_FILES['uploadfile']['type']= $files['uploadfile']['type'][$i];
$_FILES['uploadfile']['tmp_name']= $files['uploadfile']['tmp_name'][$i];
$_FILES['uploadfile']['error']= $files['uploadfile']['error'][$i];
$_FILES['uploadfile']['size']= $files['uploadfile']['size'][$i];
$this->upload->initialize($this->set_upload_options());//function defination below
$this->upload->do_upload('uploadfile');
$upload_data = $this->upload->data();
$name_array[] = $upload_data['file_name'];
$fileName = $upload_data['file_name'];
$images[] = $fileName;
}
$fileName = $images;
代码中发生了什么
井 $ _ FILE ---->它是通过POST方法上传到当前脚本的项目的关联数组。进一步查看 LINK
well $_FILE---->it is an associative array of items uploaded to the current script via the POST method.for further look this LINK
它是在脚本的所有范围内可用的自动变量
it's an automatic variable avaliable within all scopes of script
function set_upload_options()
{
// upload an image options
$config = array();
$config['upload_path'] = LARGEPATH; //give the path to upload the image in folder
$config['remove_spaces']=TRUE;
$config['encrypt_name'] = TRUE; // for encrypting the name
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '78000';
$config['overwrite'] = FALSE;
return $config;
}
并且在您的HTML标记中不要忘记:
and in your html markup don't don't forget:
输入元素必须有multiple =multiple或只有多个。
Input element must have multiple="multiple" or just multiple
3. $ this-> load-> library('upload'); //加载库
3.$this->load->library('upload'); //to load library
4.回调,$ this-> upload-> do_upload()会将在给定字段名中选择的文件上传到目标文件夹。
4.The callback, $this->upload->do_upload() will upload the file selected in the given field name to the destination folder.
5.回调$ this-> upload-> data()返回与上传文件相关的数据数组,如文件名,路径,大小等。
5.And the callback $this->upload->data() returns an array of data related to the uploaded file like the file name, path, size etc.