加载is_file在codeigniter中不起作用

时间:2014-06-16 11:38:18

标签: php codeigniter

目前我正在尝试通过codeigniter中的数据数组加载文件。但是文件没有把它拿起来。

我无法将我的徽标回显到视图页面

获得它的最佳方式是什么,所以我可以将图像作为数组。

public function index() { 

if (is_file(dirname(FCPATH) . '/image/data/logo.png')) {

$data['logo'] =  dirname(FCPATH)  . '/image/' . 'data/logo.png';

} else {

$data['logo'] = '';

}

$this->load->view('theme/default/template/common/header', $data);

}

尝试准备好了

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Header extends MX_Controller {

public function index() {

    //$this->load->library('document');

    if (is_file(FCPATH) . 'image\data\logo.png') {
    $data['logo'] = FCPATH  . 'image\data\logo.png';
    } else {
    $data['logo'] = '';
    }

    $this->load->view('theme/default/template/common/header', $data);
   }

} 

查看标题文件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php echo $title;?></title>
<link rel="stylesheet" href="catalog/views/theme/default/stylesheet/stylesheet.css">
<link rel="stylesheet" href="catalog/views/theme/default/stylesheet/bootstrap.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>

<div class="container">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
    <div class="thumbnail">
        <img src="<?php echo $logo;?>" class="img-responsive">
    </div>
</div>
</div>
</div>

2 个答案:

答案 0 :(得分:0)

public function index() 
{ 
    if (is_file(FCPATH) . 'image\data\logo.png') 
    {
        $data['logo'] = FCPATH  . 'image\data\logo.png';
    } 
    else 
    {
        $data['logo'] = '';
    }
    $this->load->view('theme/default/template/common/header', $data);
}

将此..放在您的标头文件中,将此"<img src="<?php echo $logo; ?>";

答案 1 :(得分:0)

尝试在标头控制器文件中将FCPATH更改为base_url()...它可以正常工作!!

if (is_file(base_url()) . 'image/data/logo.png') {
$data['logo'] = base_url()  . 'image/data/logo.png';
} else {
$data['logo'] = '';
}