【发布时间】:2016-01-13 22:02:48
【问题描述】:
我对 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>
【问题讨论】:
-
如果您提供minimal reproducible example 将会很有用。
-
没有你的表单html代码,很难决定!!!
标签: php codeigniter