简体   繁体   English

无法上传图片-Codeigniter-PHP

[英]Unable to upload Image - Codeigniter - PHP

Cannot upload image using CI upload library. 无法使用CI上传库上传图像。 It shows no error though. 它没有显示错误。 Can I use other name for the function do_upload() ? 我可以对function do_upload()使用其他名称吗? And if it's possible then do I need to change do_upload part in this line? 如果可能的话,是否需要在此行中更改do_upload部分? $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">&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>

End 结束

you forgot the parameter in 您忘记了
$this->upload->do_upload() function $this->upload->do_upload()函数
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 $config["file_name"] = $this->input->post('imagefull_org')如果第一个解决方案不起作用,则尝试提供其他方式的图像名称

sorry but i'm not having more reputation so I can give comment. 对不起,但是我没有更多的声誉,所以我可以发表评论。

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. 希望对您有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM