2017-05-07 419 views
0

所需的库类似乎逃避了两个.php文件,尽管它是为另一个找到的。这个类(libraries/Database.php)方法在footer.php中使用。require_once无法打开流:没有这样的文件或目录

我收到的错误是这样的:

Warning: require_once(libraries/Database.php): failed to open stream: No such file or directory in D:\PHP\Projects in PHP and MySQL\talkingspace\core\init.php on line 15

Fatal error: require_once(): Failed opening required 'libraries/Database.php' (include_path='C:\xampp\php\PEAR') in D:\PHP\Projects in PHP and MySQL\talkingspace\core\init.php on line 15

的init.php:

<?php 
// start session since we use it on every page 
session_start(); 

// config file 
require_once('config/config.php'); 

// helper functions 
require_once('helpers/db_helper.php'); 
require_once('helpers/format_helper.php'); 
require_once('helpers/system_helper.php'); 

// for autoload of classes 
function __autoload($class_name) { 
    require_once('libraries/'.$class_name.'.php'); 
} 

index.php文件中正确显示:

<?php require('core/init.php'); ?> 
<?php 
// create Topic object 
$topic = new Topic(); 
// get Template class 
$template = new Template('templates/frontpage.php'); 
// assign vars 
$template -> topics = $topic -> getAllTopics(); 
$template -> totalTopics = $topic -> getTotalTopics(); 
$template -> totalCategories = $topic -> getTotalCategories(); 
// display template 
echo $template;  

它的模板文件

<?php include 'includes/header.php'; ?>       
<ul id="topics"> 
<?php if ($topics) : ?> 
<?php foreach($topics as $topic) : ?> 
    <li class="topic"> 
     <div class="row"> 
      <div class="col-md-2"> 
       <img class="avatar pull-left" src="images/avatars/<?php echo $topic -> avatar; ?>" /> 
      </div> 
      <div class="col-md-10"> 
       <div class="topic-content pull-right"> 
        <h3><a href="topic.html"><?php echo $topic -> title; ?></a></h3> 
        <div class="topic-info"> 
         <a href="topics.php?category=<?php echo urlFormat($topic -> category_id); ?>"><?php echo $topic -> name; ?></a> >> <a href="topics.php?user=<?php echo urlFormat($topic -> user_id) ?>"><?php echo $topic -> username; ?></a> >> Posted on: <?php echo formatDate($topic -> create_date); ?> 
         <span class="badge pull-right"><?php echo replyCount($topic -> id); ?></span> 
        </div> 
       </div> 
      </div> 
     </div> 
    </li> 
<?php endforeach; ?> 
</ul> 
<?php else : ?> 
    <p>No topics to display</p> 
<?php endif; ?> 
<h3>Forum Statistics</h3> 
<ul> 
    <li>Total Number of Users: <strong>52</strong></li> 
    <li>Total Number of Topics: <strong><?php echo $totalTopics; ?></strong></li> 
    <li>Total Number of Categories: <strong><?php echo $totalCategories; ?></strong></li> 
</ul> 
<?php include 'includes/footer.php'; ?> 

服务良好,但是类似的模板文件失败并带有两个其他.php文件。这里有一个(register.php):

<?php require('core/init.php'); ?> 
<?php 
// get Template class 
$template = new Template('templates/register.php'); 
// assign vars 
$template -> title = 'Create an Account'; 
// display template 
echo $template; 

和它的模板是:

<?php include 'includes/header.php'; ?> 
    <form role="form" enctype="multipart/form-data" method="post" action="register.php"> 
     <div class="form-group"> 
      <label>Name<sup>*</sup></label> 
      <input type="text" class="form-control" name="name" placeholder="Enter Your Name"> 
     </div> 
     <div class="form-group"> 
      <label>Email Address<sup>*</sup></label> 
      <input type="email" class="form-control" name="email" placeholder="Enter Your Email Address"> 
     </div> 
     <div class="form-group"> 
      <label>Choose Username<sup>*</sup></label> 
      <input type="text" class="form-control" name="username" placeholder="Create A Username"> 
     </div> 
     <div class="form-group"> 
      <label>Password<sup>*</sup></label> 
      <input type="password" class="form-control" name="password" placeholder="Enter A Password"> 
     </div> 
     <div class="form-group"> 
      <label>Confirm Password<sup>*</sup></label> 
      <input type="password" class="form-control" name="password2" placeholder="Enter Password Again"> 
     </div> 
     <div class="form-group"> 
      <label>Upload Avatar</label> 
      <input type="file" name="avatar"> 
      <p class="help-block"></p> 
     </div> 
     <div class="form-group"> 
      <label>About Me</label> 
      <textarea id="about" rows="6" cols="80" class="form-control" name="about" placeholder="Tell us about yourself (Optional)"></textarea> 
     </div> 
     <input name="register" type="submit" class="btn btn-default" value="Register" /> 
    </form> 
<?php include 'includes/footer.php'; ?> 

请协助。我尝试了一些解决方案,在这里贴出来无济于事。 XAMPP文件夹是C:\上的默认文件夹,而项目文件夹位于另一个驱动器上。

+0

权限问题可能是 – Mehdi

+0

问题是,相同的代码适用于一个.php文件而不会为其他两个人。如果这有助于确定问题,那么教练有同样的问题,然后他替换模板的html代码,问题就消失了。 –

+0

在init.php中?我应该把它放在哪里? –

回答

1

页脚正确显示,每一页上用的init.php变化:

function __autoload($class_name) { 
    require_once('/PHP/Projects in PHP and MySQL/talkingspace/libraries/'.$class_name.'.php'); 
} 

httpd.conf中的默认的DocumentRoot和目录更改为

DocumentRoot "D:/PHP" 
<Directory "D:/PHP"> 

config.php文件定义BASE_URI as define("BASE_URI", "http://".$_SERVER['SERVER_NAME']."/Projects in PHP and MySQL/talkingspace/");

相关问题