Reputation: 15
Cannot upload image using CI upload library. It shows no error though. Can I use other name for the function do_upload()
? And if it's possible then do I need to change do_upload part in this line? $this->upload->do_upload();
//Upload library and file helper defined in autoload.//
function updatemember($id)
{
if($this->input->post('imagefull_org')) {
$config['upload_path'] ='./assets/upload/members';
$config["allowed_types"] = 'jpg|jpeg|png|gif';
$config["file_name"] = $this->input->post('imagefull_org');
$config["max_size"] = 2048;
$config["max_width"] = 400;
$config["max_height"] = 400;
$this->upload->initialize($config);
$this->upload->do_upload();
$datai = array('upload_data' => $this->upload->data());
//print_r($datai);exit();
if(!$this->upload->do_upload()) {
$this->session->set_flashdata('ok_message',$this->upload->display_errors());}
}
//codes...
}
View: Here is what my view looks like.
<div class="col-md-12 col-sm-12 form-group">
<?php echo form_label('Organization logo')?>
<?php echo form_upload('imagefull_org')?><br/><span class="display_message"> Image Size must be 200 X 200px (less than 2MB)</span>
<?php if(!empty($u->imagefull_org)){?>
<?php echo form_hidden('imagechk_org', $u->imagefull_org)?>
<img src="<?php echo base_url().'assets/upload/members/'.$u->imagefull_org?>" width="50px"/>
<br><p style="font-weight: bold;font-size: 16px;color: #2A4D79;">
<a href="<?php echo base_url().'account/imgunlink/'.$u->id.'/'.$u->imagefull_org.'/'.'imagefull_org'?>" class="btn">Delete Image</a></p>
<?php }?>
</div>
End
Upvotes: 0
Views: 497
Reputation: 3584
Make sure to use
form_open_multipart()
And try to set filename to
$config["file_name"] = $_FILES["imagefull_org"]["name"];
Finally,
$this->upload->do_upload('imagefull_org');
Edit
Try to check
if (isset($_FILES["imagefull_org"])) {
}
instead of
if ($this->input->post('imagefull_org')) {
}
Hope it will be useful for you.
Upvotes: 0
Reputation: 424
you forgot the parameter in
$this->upload->do_upload()
function
try this
$this->upload->do_upload('imagefull_org')
other wise problem in
$config["file_name"] = $this->input->post('imagefull_org')
try to give other way of image name if first solution is not work
sorry but i'm not having more reputation so I can give comment.
Upvotes: 1