douren5898 2012-04-01 17:49 采纳率: 100%
浏览 95

PHP include语句不包括使用相对路径的文件夹中的文件

I'm teaching myself website development and taught myself php and html. When I originally started this, I designed my website on apache running on windows xp. Once I got a majority of the bugs worked out, I loaded it onto a free server hosting site and everything was hunky dory.

Unfortunately, windows died (corrupted file in my system32 folder) and I'm now running Linux Mint. I just installed apache2, php, and mysql onto it so I can continue my website development, but here is the problem:

To save time, I have php include my header and footer html files using an include statement like so:

<?php include("./dir/file1.html");?>

This worked for both windows and the free server (which I believe is running a version of Linux, but don't quote me on that). However, it's not working on my machine anymore. This works:

<?php include("./file2.html");?>

but I'd really not like to refracter every webpage that I have. How can I get my include statements to include files in folders in relative paths again?

Things I have tried:

I've change the include_path to point to dir, to no avail.

I've tried absolute paths, but that didn't work either.

I've sifted through both apache.conf and php.ini looking for anything that might prevent it from reading.

Double checked the folder and file permissions to make sure it can be read.

Any and all advice will be appreciated, many thanks in advance.

UPDATE

using require gives me the error:

The website encountered an error while retrieving http://localhost/. It may be down for maintenance or configured incorrectly.

Which is not very helpful.

There are no errors using just the include statement.

There is a ".:" in my include_path.

Final Update

After a lot of trial and error, I've concluded that the problem doesn't involve php or the include statement at all, but rather with the apache server not allowing access to sub directories for some reason. This question is now moot and should be closed.

  • 写回答

1条回答 默认 最新

  • dtml3340 2012-04-01 17:58
    关注

    For including file using relative path, make sure there is "." in your include_path, set it in php.ini or in your script:

    set_include_path( ".:" . get_include_path());
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?