dqr91899 2013-03-26 19:45
浏览 73
已采纳

include仅在文件位于同一目录时才起作用

I have this site I'm making. When I include a php file from the same folder it works but when I do

<?php include('/ioanblog/appstore/header.php');?> 

it doesn't work or

<?php include('http://www.domain.co.uk/appstore/header.php');?> 

that isn't working either.

All the header is holding is a style sheet and Piwik code, it will also hold navigation.

enter image description here

  • 写回答

4条回答 默认 最新

  • duandongji2231 2013-03-26 19:47
    关注

    Read the documentation on relative paths.

    If a path is defined — whether absolute (starting with a drive letter or \ on Windows, or / on Unix/Linux systems) or relative to the current directory (starting with . or ..) — the include_path will be ignored altogether. For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file.

    You are using /ioanblog/… which is an absolute path. I suspect your site is in /var/www/public_html/ioanblog/… or /home/user/ioanblog/… or something similar, not in /ioanblog/…. You should remove the first / making it a relative instead of an absolute path. You might have to go "up" to parent directories like ../contents/header.php or ../../contents/header.php for the actual file.

    As pointed out by brbcoding it should probably be ../../header.php. But first make sure you understand absolute/relative paths!

    You might also want to read up on realpath() to 'convert' relative paths to absolute paths.

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

报告相同问题?

悬赏问题

  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在