2010-08-18 62 views
0

問題PHP不承認CSS和東西

Project1.php不顯示:CSS,拇指和側邊欄navegation

我不知道什麼是錯呢?

網站結構:

giving 
    | - - css 
    | - - footer.inc.php 
    | - - header.inc.php 
    | - - index.php 
    | - - portfolio 
       | - - print 
         | - - images.inc.php 
         | - - img 
           | - - main 
             | - - project1.jpg 
             | - - project2.jpg 
           | - - thumbs 
             | - - project1.png 
             | - - project2.png    
         | - - project1.php 
         | - - project2.php 
       | - - print.php 

     | - - web 
       | - - images.inc.php 
       | - - img 
       .... 
       | - - web.php 

       | - - consulting 
       | - - consulting.php 

       | - - illustration 
       | - - illustration.php 

在index.php看起來像:

<?php  
       $page = $_GET['page']; 

       if (!$page) { 
       $page = 'page'; 
       }   

      include("header.inc.php"); 
      include("portfolio/".$page.".php"); 
      include("footer.inc.php"); 
?> 

鏈接到網頁的大拇指:

<ul id="thumbs"> 

    <?php 
    $dir = 'portfolio/print/img/thumbs/'; 
    $path = 'portfolio/print/'; 

    $fileTypes = array('.png', '.jpg', '.gif'); 

    foreach($fileTypes as $extension) { 
     foreach(glob($dir . '*' . $extension) as $projectImage) { 
      $projectName = basename($projectImage, $extension); 
      $project = $projectName . '.php'; 
      echo '<li> 
       <a href="'. $path . $project . '"> 
       <img src="' . $projectImage . '" alt="' . $projectName . '" /> 
       <strong>'. $projectName .'</strong> 
       </a> 
       </li>'; 
     } 
    } 
// Thanks to Maggie for the Help! 
?> 

Project1.php:

我包括footer.in c.php /的header.inc.php/images.inc.php像這樣:

<?php 
    $path = $_SERVER['DOCUMENT_ROOT']; 
    $path .= "/giving/header.inc.php"; 
    include_once($path); 
?> 
<?php 
    $path = $_SERVER['DOCUMENT_ROOT']; 
    $path .= "giving/portfolio/print/images.inc.php"; 
    include_once($path); 
?> 
<!-- Content --> 
<!-- Title - Print --> 
    <p class="title">Print <span id="clients_name">Print 1</span></p>        
    <h2 id="img"> 
     <?php 

     $main_dir = 'img/main/'; 
     $scan = scandir ($main_dir); 

     echo '<img src="' . $main_dir . $scan[3] . ' "alt ="images" />'; 
     ?> 
    </h2> 
    <p class="brief"> 
     <span>Brief:</span> He felt a slight itch up on his belly; pushed himself slowly up on his back towards the headboard so that he could lift his head better; found where the itch was, and saw that it was covered with lots of little white spots which he didn't know what to make of. 
     </p>   
    <h4><a title="Go Live" href="#">Live Project</a></h4> 

<?php 
    $path = $_SERVER['DOCUMENT_ROOT']; 
    $path .= "/giving/footer.inc.php"; 
    include_once($path); 
?> 

的header.inc.php

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="UTF-8"> 
     <title>Giving - 1st theme</title> 
     <link href="css/layout.css" type="text/css" media="screen, projection" rel="stylesheet"> 
    </head> 
    <body> 
    <div id="portfolio"> 
    <div class="content"> 
     <h1><a href="#home" title="Panel's Home Page">Panels Logo Portfolio</a></h1> 
     <div id="projects_services"> 
      <div id="print_section"> 
       <?php // $currentPage = basename($_SERVER['SCRIPT_NAME']); ?> 
       <ul id="sidebar"> 


        <?php 

         $sections = array("Print", "Web", "Illustration", "Consulting"); 

         foreach ($sections as $row) { 
          echo "<li><a href=\"index.php?page=$row\""; 

          if ($row == $page) { 

           echo "class=\"selected\""; 
          } 

          echo ">$row</a></li>\n";     
         } 


        ?> 

       <!-- <li> 
       <a href="print.php" <?php // if ($currentPage == 
       //     'index.php?page=print.php') {echo 'class="selected"';} ?> title=" ">Print</a> 
       </li>   
       <li> 
       <a href="index.php?page=web.php" <?php // if ($currentPage == 
       //     'index.php?page=web.php') {echo 'class="selected"';} ?> title=" ">Web</a> 
       </li> 
       <li> 
       <a href="index.php?page=illustration.php" <?php // if ($currentPage == 
       //     'index.php?page=illustration.php') {echo 'class="selected"';} ?> title=" ">Illustration</a> 
       </li> 
       <li> 
       <a href="index.php?page=consulting.php" <?php // if ($currentPage == 
       //     'index.php?page=consulting.php') {echo 'class="selected"';} ?> title=" ">Consulting</a> 
       </li> --> 
       </ul><!-- End sidebar--> 

唷!

謝謝!

+1

代替所有這些,如果您只是發佈了呈現的HTML,這將有助於我們看到文檔''中的內容。 PHP與CSS無關。 – 2010-08-18 12:28:55

+0

我認爲這很重要,因爲我正在使用includes,PHP在根中讀取的內容比HTML更深。謝謝 – Martin 2010-08-18 12:49:12

回答

2

您的標題鏈接到相對URL(css/layout.css)。使其鏈接到絕對路徑(/css/layout.css)。

+0

它沒有幫助。 – Martin 2010-08-18 12:42:52

+0

然後,您需要更改絕對路徑以適合您的Web服務器設置。如果應用程序的根目錄是'yourdomain.com/myapp /',那麼它需要是'/ myapp/css/layout.css'。 – 2010-08-18 13:32:14

+0

謝謝Lèsemajesté – Martin 2010-08-18 15:10:34

3
<?php  
       $page = $_GET['page']; 

       if (!$page) { 
       $page = 'page'; 
       }   

      include("header.inc.php"); 
      include("portfolio/".$page.".php"); 
      include("footer.inc.php"); 
?> 

這太可怕了,請檢查用戶輸入,如果你不想讓別人查看你的/ etc/passwd和其他文件。

如果認爲本地化您的問題的最佳方式是簡單打印到瀏覽器,您的腳本正在尋找CSS文件。你也可以輸出dirname(__ FILE__)並比較路徑,也許你會發現區別。

+0

是的,我之前聽說過一個。這就是爲什麼我會使用 <?php // $ currentPage = basename($ _ SERVER ['SCRIPT_NAME']); ?> 謝謝! – Martin 2010-08-18 12:25:10

+0

我會試試看。再次感謝! – Martin 2010-08-18 12:32:05