2014-02-15 98 views
0

我知道這個問題已經被問過,但即使讀其他職位後,我無法弄清楚怎麼回事...PHP包括和要求不工作

請看看我的代碼結構,看我在做什麼錯..

文件夾結構:

的index.php

(文件夾 - 包括)的header.php

(文件夾 - 瀏覽)博客。 PHP,ecommerce.php,other.php

(文件夾 - 核心)的init.php

我想包括header.php中從包括在瀏覽文件夾中的文件夾blog.php的。以下是我的header.php代碼。位於

頭文件還包括文件夾

<!DOCTYPE html> 
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]--> 
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]--> 
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]--> 
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]--> 
<head> 

    <!-- Basic Page Needs 
    ================================================== --> 
    <meta charset="utf-8"> 
    <title>Web Awwards | Web Gallery | Submit your site</title> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <!-- Mobile Specific Metas 
    ================================================== --> 
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 

    <!-- CSS 
    ================================================== --> 
    <link rel="stylesheet" type="text/css" href="../css/base.css"> 
    <link rel="stylesheet" type="text/css" href="../css/skeleton.css"> 
    <link rel="stylesheet" type="text/css" href="../css/layout.css"> 
    <link rel="stylesheet" type="text/css" href="../css/styles.css"> 
    <link rel="stylesheet" type="text/css" href="../css/menu.css"> 
    <link rel="stylesheet" type="text/css" href="../css/submission.css"> 

    <!--[if lt IE 9]> 
     <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
    <![endif]--> 

    <!-- Favicons 
    ================================================== --> 
    <link rel="shortcut icon" href="images/favicon.ico"> 
    <link rel="apple-touch-icon" href="images/apple-touch-icon.png"> 
    <link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png"> 
    <link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png"> 

</head> 
<body> 
<?php 
    require_once('core/init.php'); 
?> 
<!-- Menu Horizontal --> 
<div class="horizontal"> 
    <div class="webName"> 

和瀏覽文件夾blog.php的文件代碼:

<?php 
    include './includes/header.php'; 
?> 
<!-- TODO PHP Scripts --> 
<div class="category nine columns"> 
    <div class="category-img"> 
     <img src="css/img/webImg/screen1.png" alt="Site Description"/> 
    </div> 
    <h3> Web Name </h3> 
    <h5> Designed By: Tautvydas Slegaitis </h5> 
    <h7> Designers url </h7> 
    <div class="vote"> 
     <h4> Vote for my site </h4> 
     </br> 
     <a href="#"> Love it </a> 
     <a href="#"> Nope, Not for me </a> 
    </div> 
</div> 

</div><!-- Close Container Div --> 
<div class="footer"> 


</div> 



</body> 
</html> 

但它無法正常工作。我不知道爲什麼,...請幫我解決它在過去的兩天裏殺了我。 「警告:包括(./ includes/header.php):無法打開流:沒有這樣的文件或目錄 - 在第2行警告:包括():失敗打開'。 /includes/header.php在 '列入(include_path中=':') - 第2行「

的init.php代碼:

<?php 
session_start(); 

$GLOBALS['config'] = array(
    'mysql' => array(
     'host' => 'localhost', 
     'username' => 'root', 
     'password' => 'root', 
     'db' => 'webAwwards' 
    ), 
    'remember' => array(
     'cookie_name' => 'hash', 
     'cookie_expire' => 604800 
    ), 
    'session' => array(
     'session_name' => 'user' 

    ) 
); 
// TODO Remove parenthesis in require once if doesnt work 
spl_autoload_register(function($class) { 
    require_once('classes/' . $class . '.php'); 
}); 

require_once('/functions/sanitise.php'); 

?> 
+1

'/'應該是''../。 – christopher

+0

如果我添加../它包括頭,但然後停止執行blog.php的其餘部分,如果我在瀏覽器中查看源代碼只顯示header.php代碼 – Tauciokas

+0

嘗試使用'require'而不是'include'。 – christopher

回答

2

嘗試:

include('../test/header.php'); 

它的工作原理罰款在我身上。

Edit:如果沒有你的情況下,嘗試糾正你init.php的路徑:

require_once('../core/init.php'); 
+0

如果我改正我的init.php的路徑,因爲你建議沒有打開的文件。我知道這是有道理的,但我不知道爲什麼會發生這種情況 – Tauciokas

+0

您是否試圖首先刪除它,只是爲了檢查您是否可以檢查是否已經檢查了'include('../ test/header.php');'是否正確? – Vainglory07

+0

正確的問題是,然後在頭文件中包含init.php :) – Tauciokas