简体   繁体   English

PHP无法识别CSS和其他内容

[英]PHP does not recognize CSS and stuff

Problems 问题

Project1.php does not show: CSS, thumbs and sidebar navegation Project1.php不显示:CSS,拇指和侧边栏导航

I do not know what is wrong with it? 我不知道这是怎么回事?

Site Structure: 网站结构:

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

The Index.php looks like: Index.php看起来像:

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

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

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

The Thumbs linking to pages: 拇指链接到页面:

<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: Project1.php:

I'm including footer.inc.php / header.inc.php / images.inc.php like so: 我像这样包含footer.inc.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 的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-->   

Phew! 唷!

Thank you! 谢谢!

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

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

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

This is horrible, do some check of user input, if you don't want to someone view your /etc/passwd and other files. 如果您不想让别人查看您的/ etc / passwd和其他文件,这太可怕了,请检查一下用户输入。

If think the best way to localise your problem is to simple print to browser, where your script is looking to CSS file. 如果您认为解决问题的最佳方法是简单打印到浏览器,而您的脚本正在寻找CSS文件。 Also you can output dirname(__ FILE__) and compare paths, maybe you will find difference. 您也可以输出dirname(__ FILE__)并比较路径,也许您会发现差异。

Your header is linking to a relative URL ( css/layout.css ). 您的标头链接到相对URL( css/layout.css )。 Make it link to an absolute path ( /css/layout.css ). 使它链接到绝对路径( /css/layout.css )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM