dtny30176 2019-03-11 06:20
浏览 87

php相对路径失败

I have been setting up a new web server to replace an aging one and I am having some problems with relative paths that work on the existing server. The existing server is Centos 6 with php 5.6, however the new server is Centos 7 with the same php version. I should also mention that both servers run WHM/cPanel with a single user (solo) licence.

I have several folders one level above the public_html folder that contain some include files and also some php files that are run from cron jobs. I put these here as there is never any need for them in the public_html folder.

// Example folder structure
-includes
-cjobs
-public_html
   -includes
   -css
   -js
   index.php

On the existing server, the following works ok on a file in the cjobs folder include "../public_html/includes/mail_include.php";, however on the new server it fails. I have ended up using include_once (dirname(__FILE__) . "/../includes/mail_include.php"); and also had to relocate the cjobs folder into the public_html folder. Note that full paths do work ok, so /home/username/includes/mail_include.php does always work, but I don't want to hard code the paths.

I feel that there may be some small configuration setting in php that I have not changed, but I just have not been able to figure out why I need to include the files this way. It means I need to modify thousands of files just so they will work on the new server which is proving to be a real pain.

Any advice is appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥15 帮我写一个c++工程