在Codeigniter中读取空文件图像

时间:2015-07-12 10:31:02

标签: php codeigniter file-upload

我需要使用或不使用用户的照片资料更新个人资料user,此处我的代码在视图中

<input type="file" name="file_foto" class="form-control">

我如何读取文件是否为空,在更新数据与图像或没有图像时选择。 以及如何使unlink图像删除Codeigniter中的previouse图像。感谢

这是我的控制器

if (empty($_FILES['file_foto']['name'])) {
            $data_profil = array(
                'name'=>$name
                );
        }else{
            $foto_up = $this->do_upload_image('file_foto');
            $data_profil = array(               
                'name'=>$name,
                'foto'=>$foto_up['file_name']
                );

        }

2 个答案:

答案 0 :(得分:1)

if($_FILES['file_foto']['name'])){
code to upload image
}

答案 1 :(得分:0)

哦,所有,我的问题现在解决了,只需使用此代码

if (empty($_FILES['file_foto']['name']))