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 目标计数模型训练过程中的问题
  • ¥100 Acess连接SQL 数据库后 不能用中文筛选
  • ¥15 用友U9Cloud的webapi
  • ¥20 电脑拓展屏桌面被莫名遮挡
  • ¥20 ensp,用局域网解决
  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败