使用codeigniter php从uploads文件夹向页面显示图像

时间:2016-02-22 04:17:31

标签: php codeigniter

我正在尝试在页面中显示上传的图片。我在上传图片时使用了dropzone。

控制器:

public function do_uploadlogo($id){
 $restologo=$_POST['restologo'];
    $tempFile = $_FILES['file']['tmp_name'];
    $fileName = $_FILES['file']['name'];
    $targetPath = getcwd() . '/uploads/restaurants/logos/';
    $targetFile = $targetPath . $fileName ;
    $data = array(
        'restologo' => 'uploads/restaurants/logos/'.$fileName
    );
    $this->load->database('findiningcebu');
    $this->db->where('id', $id);
    $this->db->update('restaurants',$data);
    move_uploaded_file($tempFile, $targetFile);
 }
 public function addrestologolink($id){
    $data = array(

            "action" => base_url('/index.php/AdminController/do_uploadlogo/'.$id), 
            "data" => $this->db->get_where('restaurants',array('id'=>$id))  
    );   

    $this->load->view('admin/logo',$data);
}

查看

<div class="del" style="padding-left: 15px">Current Logo:</div>
<div class="del" style="padding-left: 15px"><img src="<?=base_url().$restologo?>" /></div>

请帮忙!

1 个答案:

答案 0 :(得分:1)

使用此代码

<div class="del" style="padding-left: 15px">
<?php
 echo'<img src="' . base_url().'uploads/restaurants/logos/' . $restologo . '">';
?>