我更新鲜的codeignite,我想将图像和视频上传到图像和视频文件夹。但图像和视频上传到同一个文件夹。
我使用if条件尝试了很多次,但没有任何改变。
请帮助解决这个问题。
这是我的代码: -
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$data['data'] = "";
$data['content']=$this->load->view('cmsblock/cmsblock',$data,TRUE);
$this->load->view('includes/main',$data);
}
function do_upload()
{
foreach ($_FILES as $key => $value) {
if (!empty($value['tmp_name'])) {
if($key == "file1") {
$config['upload_path'] = 'uploads';
$config['allowed_types'] = 'mp4|3gp|gif|jpg|png|jpeg|pdf';
$config['max_size']='';
$config['max_width']='200000000';
$config['max_height']='1000000000000';
$this->load->library('upload',$config);
if ( ! $this->upload->do_upload($key)) {
$error = array('error' => $this->upload->display_errors());
//failed display the errors
} else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('cmsblock/success', $data);
}
}
if($key == "file2") {
$config11['upload_path'] = 'videos';
//$config11['upload_path'] = 'uploads';
$config11['allowed_types'] = 'mp4|3gp|gif|jpg|png|jpeg|pdf';
$config11['max_size']='';
$config11['max_width']='200000000';
$config11['max_height']='1000000000000';
$this->load->library('upload',$config11);
if ( ! $this->upload->do_upload($key)) {
$error = array('error' => $this->upload->display_errors());
//failed display the errors
} else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('cmsblock/success', $data);
}
}
}
}
}
} ?>
这是我的HTML文件代码:
<?php echo form_open_multipart('admin/upload/do_upload');?>
<input type="file" name="file1" id="file_1" />
<input type="file" name="file2" id="file_2"/>
<br/><br/>
<input type="submit" value="upload" />
</form>
答案 0 :(得分:0)
尝试使用
$this->upload->initialize($config11);
而不是
$this->load->library('upload',$config11);
if($key == "file2"){...
部分中的