zoukankan      html  css  js  c++  java
  • 如何正确使用$_SERVER['DOCUMENT_ROOT']识别该路径的文件

    echo $_SERVER['DOCUMENT_ROOT'];

    这时输出当前文件所在的路径 D:/phpStudy/WWW/study/php&mysql 

     $_SERVER['DOCUMENT_ROOT']/orders.txt 这时候以为输出的路径为 D:/phpStudy/WWW/study/php&mysql/orders.txt 

    但是通过echo 输出的为结果为:

    Notice: Use of undefined constant orders - assumed 'orders' in D:phpStudyWWWstudyphp&mysql	est.php on line 9
    
    Warning: Division by zero in D:phpStudyWWWstudyphp&mysql	est.php on line 9
    
    Notice: Use of undefined constant txt - assumed 'txt' in D:phpStudyWWWstudyphp&mysql	est.php on line 9
    txt

    我们给 orders.txt 两边加上双引号试试,变成 

    $_SERVER['DOCUMENT_ROOT'].”/orders.txt“ 

    这时才能正确识别orders.txt的地址

     D:/phpStudy/WWW/study/php&mysql/orders.txt 

    还有一种方式就是给 $_SERVER['DOCUMENT_ROOT'] 两边加上大括号,然后总的路径打上双引号

    "{$_SERVER['DOCUMENT_ROOT']}/orders.txt"

    这样也能正确输出orders.txt的地址

  • 相关阅读:
    fatal: protocol error: bad line length character: This
    httpd: apr_sockaddr_info_get() failed for bogon
    Go语言函数
    Go语言流程控制
    进制转换
    Go语言运算符
    LeetCode 62. Unique Paths
    LeetCode 61. Rotate List
    asdfasdfasdf
    开发者,别让自己孤独
  • 原文地址:https://www.cnblogs.com/jacson/p/4849221.html
Copyright © 2011-2022 走看看