问题是当上传图像时,每次都显示相同的错误“上传路径似乎无效”。尝试了这么多的解决方案,但仍然有相同的问题。请帮助。
控制器:
public function updateprofile()
{
/***get current user data***/
$this->load->model('Admin_main','userinfo');
$data=$this->userinfo->getuserdata();
$this->load->model('Admin_main','updateprofile');
$result=$this->updateprofile->updatemyprofile();
if($data->identity=='admin')
{
redirect('admin/myprofile');
}
else
{
redirect('campuser/myprofile');
}
}
产品型号:
if($_FILES['fileToUpload']['name']!='')
{
$config["upload_path"] = './uploads/';
$config["allowed_types"] = 'jpg|jpeg|png|gif';
$config['max_width'] = 0;
$config['max_height'] = 0;
$config['max_size'] = 0;
$config['encrypt_name'] = TRUE;
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('fileToUpload')){
$uploadData = $this->upload->data();
$picture = $uploadData['file_name'];
$mypic = array('profile_pic'=>$picture);
$this->db->set($mypic);
$this->db->where('id', $userid);
$uppic=$this->db->update('mokhayam_users');
}
else
{
echo $this->upload->display_errors();
}
}
查看方式:
<form class="form-horizontal" action="admin/updateprofile" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="col-sm-2 control-label">Profile Picture</label>
<div class="col-sm-10">
<label for="fileToUpload"><img src="assets/admin/dist/img/gul.jpg" id="blah1" class="profile-user-img img-responsive img-circle"/></label><input type="file" name="fileToUpload" id="fileToUpload" onchange="$('#blah1')[0].src = window.URL.createObjectURL(this.files[0])">
</div>
</div>
<input type="hidden" name="userid" value="2">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
提前感谢。
2条答案
按热度按时间fxnxkyjh1#
如果您的codeigniter版本是3.x,请将库文件(system/library/upload.php)版本codeigniter 3.x更改为2.x,然后尝试
lymnna712#
在不更改库中任何内容的情况下,解决方案是在控制器中加载上载库后立即初始化配置,请遵循以下代码