即使它是真的,PHP也会返回

时间:2014-02-13 14:21:24

标签: php

下面是我的index.php文件源代码:

<?php
include "app/global.php";

$page = $_GET['page'];
echo $page;
?>

我的app / global.php:

<?php
global $url;
$url = 'localhost/tpl';
$theme = 'default';

include 'classes/class.template.php';
$tpl = new Template($url, $theme);
?>

我的class.template.php:

<?php
class Template {
    public function __construct($url, $theme) {
        if(file_exists($url . '/app/themes/' . $theme . '/header.php')) {
            include $url . '/app/themes/' . $theme . '/header.php';
        } else {
            echo "File not found!";
        }
    }
}
?>

所以我的问题是,如果我试图检查文件是否存在,位置是:

http://localhost/tpl/app/themes/default/header.php

当我使用链接访问它时它可以工作,但是当我尝试用PHP检查它时它返回false。你认为这可能是什么解决方案?

4 个答案:

答案 0 :(得分:1)

您不希望包含网址!您需要包含本地文件http://localhost/tpl/app/themes/default/header.php可以是通过HTTP访问文件的URL,但您希望使用磁盘上的文件路径 。例如

/var/www/tpl/app/themes/default/header.php

答案 1 :(得分:0)

localhost是主机名,不是路径的一部分,因此您不应将其包含在$url中。

答案 2 :(得分:0)

修正了它。位置错了。

答案 3 :(得分:-2)

file_exists适用于绝对路径。你写了网址。它必须类似于“D:/ wamp / www / your_project / your_file”