【问题标题】:PHP does not recognize CSS and stuffPHP 不识别 CSS 和东西
【发布时间】:2010-08-18 12:21:02
【问题描述】:

问题

Project1.php 不显示:CSS、拇指和侧边栏导航

不知道有什么问题?

网站结构:

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!
?>

项目1.php:

我包括 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

<!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-->   

呸!

谢谢!

【问题讨论】:

  • 而不是所有这些,如果您只是发布呈现的 HTML 会有所帮助,这样我们就可以看到文档 &lt;head&gt; 中的内容。 PHP 与 CSS 无关。
  • 我认为这很重要,因为我正在使用包含,并且 PHP 在根目录中的读取比 HTML 更深。谢谢

标签: php arrays function


【解决方案1】:
<?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__) 和比较路径,也许你会发现不同。

【讨论】:

  • 是的,我以前听说过。这就是为什么我会使用 谢谢!
【解决方案2】:

您的标头链接到一个相对 URL (css/layout.css)。使其链接到绝对路径 (/css/layout.css)。

【讨论】:

  • 然后您需要更改绝对路径以适合您的 Web 服务器设置。如果应用程序的根是yourdomain.com/myapp/,那么它需要是/myapp/css/layout.css
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-17
  • 2018-12-03
  • 1970-01-01
  • 1970-01-01
  • 2018-03-08
  • 2019-01-25
  • 1970-01-01
相关资源
最近更新 更多