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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题