dongmian5325 2013-03-03 21:57
浏览 45
已采纳

require_once()链接超出子目录时出错[关闭]

I am trying to require_once() a file that is in a folder located in my root... I am requiring this file from a file that is in another sub-folder of my root.

  • Root

    • includes

      • include_all.php
    • my

      • question_history.php

This is my/question_history.php:

 <?php require_once("./includes/include_all.php"); ?>

I am getting these errors:

Warning: require_once(./includes/include_all.php) [function.require-once]: failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/AnswerTree2/my/question_history.php on line 3

Fatal error: require_once() [function.require]: Failed opening required './includes/include_all.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php:/Applications/XAMPP/xamppfiles/lib/php/pear') in /Applications/XAMPP/xamppfiles/htdocs/AnswerTree2/my/question_history.php on line 3

I am kinda new to keeping files in different folders as I used to just put everything in root folder. bad practice i know. but anyway hope this is enough detail.

  • 写回答

3条回答 默认 最新

  • douwu8524 2013-03-03 21:59
    关注

    The right code would be:

    <?php require_once("../includes/include_all.php"); ?>
    

    The error comes, becouse ./ requires the file to be in the same folder, so your code would require the includes folder be in the my folder.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?