我有一个主页正确显示的网站,但是当我点击子页面时出现以下错误:
警告:require_once(../php/DB.php) [function.require-once]:无法打开流:第 75 行/home/user/public_html/config.php 中没有这样的文件或目录
fatal error :require_once() [function.require]: Failed opening required '../php/DB.php' (include_path='.:/home/content/74/9419674/html/PEAR/PEAR')在/home/user/public_html/config.php 第 75 行
我在主页上收到此错误,但能够追踪到源头并更正链接。我假设它没有正确读取链接,但我已经把头撞在墙上足够长的时间了。
配置文件:
require_once '../php/DB.php';
$dsn = 'mysql://username:password@host/database';
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);
$db =& DB::connect($dsn, $options);
$db->setOption('autofree', true);
$db->setOption('persistent', true);
$db->setFetchMode(DB_FETCHMODE_ASSOC);
if (PEAR::isError($db)) {
echo 'Standard Message: ' . $db->getMessage() . "\n";
echo 'Standard Code: ' . $db->getCode() . "\n";
echo 'DBMS/User Message: ' . $db->getUserInfo() . "\n";
echo 'DBMS/Debug Message: ' . $db->getDebugInfo() . "\n";
die($db->getMessage());
}
子索引文件:
<?php
include "../config.php";
$titleText = "The Store";
$titleImage = "Store.T.gif";
include "../includes/header.php";
include "getcats.php";
$bannerImage = "Ban_Store.jpg";
include "../includes/top.php";
?>
我的文件结构是默认的 GoDaddy cPanel 结构。配置文件在 public_html 中,索引文件在子目录中。你能提供的任何帮助都会很棒。提前致谢!
最佳答案
脚本不是从子页面的文件夹执行的,而是(可能)从根文件夹(document-root,即 public_html)执行的。为避免这样的“错误”,请使用绝对路径加载:
require __DIR__ . '/../config.php';
或者,查看 PHP 类自动加载。
关于php - 首页显示,但子页面显示require_once错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32513279/