dongwen2896 2018-05-01 03:19
浏览 6

PHP包括在错误的地方搜索

So I have a web application hosted on a site. The web root (I.E. the files the client can access) is the public_html folder. However, I need to include files outside of the public_html folder. I do this using php include. I get an error no such file or directory. When it shows me the path it is still looking in the public_html folder, which is not where I need it looking. The code looks like this:

<?php include('../eCommerceCore/shoppingCart.php');?>

I need it to look up one level but it will not search outside of public_html. Also, the file containing the line of code shown above is in the public_html folder if that helps.

  • 写回答

1条回答 默认 最新

  • duanbodai5166 2018-05-01 03:25
    关注

    Sometimes the current directory isn't what you expect it to be, such as when you include a file from an included file.

    I like to use $_SERVER['DOCUMENT_ROOT'] on my includes so that I can always reference them absolutely from the root of my site:

    <?php
        include($_SERVER['DOCUMENT_ROOT']."../eCommerceCore/shoppingCart.php");
    
    ?>
    

    Or this way you can try

    <?php
        include "../eCommerceCore/shoppingCart.php";       
    ?>
    

    If your includes directory is above your document root, you can use .. to still reference from the root.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度