gre*_*row 5 arrays upload codeigniter
我试图上传多个图像,我有一个jquery插件设置,所以我可以浏览多个文件并选择它们.
我唯一的问题是访问我的控制器中的文件阵列,有谁知道我怎么做到这一点?谢谢.
视图:
<input type="file" name="userfile[]" id="userfile" class="multi" />
Run Code Online (Sandbox Code Playgroud)
小智 11
去年我在一个项目上遇到了同样的问题,经过一番搜索,我发现了一个完美的功能.
我不相信它,但不能记住我发现它的地方,所以如果有人知道请链接回作者.
确保表单包含这样的文件
<input type="file" name="userfile"/>
<input type="file" name="userfile2" />
<input type="file" name="userfile3" /> ..etc
Run Code Online (Sandbox Code Playgroud)
要么
<input type="file" name="userfile[]" />
Run Code Online (Sandbox Code Playgroud)
功能..
function multiple_upload($upload_dir = 'uploads', $config = array())
{
$files = array();
if(empty($config))
{
$config['upload_path'] = '../path/to/file';
$config['allowed_types'] = 'gif|jpg|jpeg|jpe|png';
$config['max_size'] = '800000000';
}
$this->load->library('upload', $config);
$errors = FALSE;
foreach($_FILES as $key => $value)
{
if( ! empty($value['name']))
{
if( ! $this->upload->do_upload($key))
{
$data['upload_message'] = $this->upload->display_errors(ERR_OPEN, ERR_CLOSE); // ERR_OPEN and ERR_CLOSE are error delimiters defined in a config file
$this->load->vars($data);
$errors = TRUE;
}
else
{
// Build a file array from all uploaded files
$files[] = $this->upload->data();
}
}
}
// There was errors, we have to delete the uploaded files
if($errors)
{
foreach($files as $key => $file)
{
@unlink($file['full_path']);
}
}
elseif(empty($files) AND empty($data['upload_message']))
{
$this->lang->load('upload');
$data['upload_message'] = ERR_OPEN.$this->lang->line('upload_no_file_selected').ERR_CLOSE;
$this->load->vars($data);
}
else
{
return $files;
}
}
Run Code Online (Sandbox Code Playgroud)
现在已经有一段时间了,因为我已经使用它,所以如果你需要任何额外的帮助设置它只是让我知道.
| 归档时间: |
|
| 查看次数: |
12066 次 |
| 最近记录: |