2015-04-24 66 views
0

无法使用CI上传库上传图像。它虽然显示没有错误。我可以使用function do_upload()的其他名称吗?如果可能的话,我是否需要在这一行中更改do_upload部分? $this->upload->do_upload();无法上传图像 - Codeigniter - PHP

//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... 
} 

查看: 这里是我的看法是什么样子。

<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">&nbsp;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> 

+0

您有没有机会查看文档,看看您是否正确地构建代码?没有任何错误,调试问题确实是一项艰巨的工作,特别是当我们没有(代表每个细节)关于代码的信息时。 – ilter

+0

您对./assets/upload/members有正确的权利吗?你有没有尝试使用error_reporting函数来查看你得到了什么错误?什么网络服务器日志说? – Sacx

+0

这可能是该文件夹的权限问题。 – Lakhan

回答

0

确保使用

form_open_multipart() 

并尝试文件名设置为

$config["file_name"] = $_FILES["imagefull_org"]["name"]; 

最后,

$this->upload->do_upload('imagefull_org'); 

编辑

尝试检查,而不是

if (isset($_FILES["imagefull_org"])) { 

} 

if ($this->input->post('imagefull_org')) { 

} 

希望这将是对你有用。

+0

非常感谢。有效。 :) –

+0

不客气。 –

1

你忘了
$this->upload->do_upload()功能参数

$config["file_name"] = $this->input->post('imagefull_org') 试试这个
$this->upload->do_upload('imagefull_org')
其他明智的问题给图像名称的其它方式,如果第一个解决方案是不工作

对不起,但我没有更多的声誉,所以我可以发表评论。

+0

它不工作。我尝试了$ this-> upload-> do_upload('imagefull_org')以及$ this-> upload-> do_upload($ this-> input-> post('imagefull_org')) –

+0

@NostalgicMirazAryal请尝试我现在​​的解决方案首先还要检查你是否忘记了'form_open_multipart()'来创建表单。 –