这真的很奇怪,我试图在谷歌中查看与我的问题类似的最佳建议,但我相信这些不是这个问题的答案。我正在使用默认的“用户文件”。谁能告诉我我在这里缺少什么?
我的表格结构:
<div class="panel-body">
<?php echo form_open_multipart('register','role="studentForm" class="form-horizontal'); ?>
<div class="form-group">
<label for="userfile" class="col-lg-3 col-md-3 col-sm-3 control-label">Profile Picture</label>
<div class="col-lg-9 col-md-9 col-sm-9">
<input type="file" name="userfile" size="20" id="userfile">
</div>
</div>
<button type="submit" class="btn btn-default btn-login-style btn-sm pull-right">Submit</button>
<?php echo form_close(); ?>
</div>
我的控制器的结构:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Register extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 2048;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->upload->initialize($config);
if(!$this->upload->do_upload()){
$error = array('error'=>$this->upload->display_errors());
echo $error['error'];
}else{
$uploaded_pic = $this->upload->data();
}
}
}
?>
注意:“上传”库在 autoload.php 中自动加载。