使用localhost但服务器返回“无法打开流:没有这样的文件或目录”

时间:2010-09-21 08:56:47

标签: php file-io stream

我是一个真正需要帮助的新手,一直试图让这个PHP脚本工作没有运气,当我在本地运行网站它工作但我将文件移动到服务器后我得到以下错误,希望有人能帮助我:

  

警告:include(/var/chroot/home/content/16/5976816/html/inc/header.php)[function.include]:无法打开流:/ home / content /中没有此类文件或目录第49行的16/5976816 / html / vtr / test / index.php

这是我正在使用的脚本:

<?php

    // Include the header:
    include($_SERVER['DOCUMENT_ROOT'] . '/inc/header.php');

    ?>

    <div id="contents">
        <div id="content">

            <?php
            // Define our array of allowed $_GET values
            $pass = array('intro','about','vincent-tran','philip-roggeveen','estate-planning','criminal-case','personal-injuries','bankruptcy','inmigration','deportation','family-law','litigation','corporations-and-llcs', 'payments','consultation','request-callback','contact-us');
            // If the page is allowed, include it:
            if (in_array($_GET['id'], $pass)) {
                include ($_SERVER['DOCUMENT_ROOT'] . '/inc/' . $_GET['id'] . '.php');
            }
            // If there is no $_GET['id'] defined, then serve the homepage:
            elseif (!isset($_GET['id'])) {
                include ($_SERVER['DOCUMENT_ROOT'] . '/inc/intro.php');
            }
            // If the page is not allowed, send them to an error page:
            else {
                // This send the 404 header
                header("HTTP/1.0 404 Not Found");
                // This includes the error page
                include ($_SERVER['DOCUMENT_ROOT'] . '/inc/error.php');
            }
            ?>

        </div>
    </div>
    <!-- end OutsideWrap-->

    <?php
    // Include the footer:
    include($_SERVER['DOCUMENT_ROOT'] . '/inc/footer.php');
    ?>

3 个答案:

答案 0 :(得分:0)

错误显示找不到您要包含的文件。

确保:

  • 您正在指定正确的路径
  • 目录具有正确的权限,chmod为755

您可以通过回显来检查已解决的路径:

echo $_SERVER['DOCUMENT_ROOT'] . '/inc/header.php';

据我所知,/

之后您不需要$_SERVER['DOCUMENT_ROOT']

答案 1 :(得分:0)

 if (strpos($system_folder, '/') === FALSE)
{
    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
    {
        $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
    }
}
else
{
    // Swap directory separators to Unix style for consistency
    $system_folder = str_replace("\\", "/", $system_folder); 
}

这是一个获取应用程序基本目录的函数

将$ system_folder替换为您网站的文件夹名称,如果它位于htdocs / somewebapp上

$systemfolder = "somewebapp";

答案 2 :(得分:0)

谢谢你们所有的帮助,我没有使用正确的道路。

<?php

            // Define our array of allowed $_GET values
            $pass = array('intro','about','vincent-tran','philip-roggeveen','estate-planning','criminal-case','personal-injuries','bankruptcy','inmigration','deportation','family-law','litigation','corporations-and-llcs', 'payments','consultation','request-callback','contact-us');
            // If the page is allowed, include it:
            if (in_array($_GET['id'], $pass)) {
                include ($_SERVER['DOCUMENT_ROOT'] . '/vtr/today/inc/' . $_GET['id'] . '.php');
            }
            // If there is no $_GET['id'] defined, then serve the homepage:
            elseif (!isset($_GET['id'])) {
                include ($_SERVER['DOCUMENT_ROOT'] . '/vtr/today/inc/intro.php');
            }
            // If the page is not allowed, send them to an error page:
            else {
                // This send the 404 header
                header("HTTP/1.0 404 Not Found");
                // This includes the error page
                include ($_SERVER['DOCUMENT_ROOT'] . '/vtr/today/inc/error.php');
            }
            ?>

现在工作得很好。