php PHP中的服务器文档根路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15211231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Server Document Root Path in PHP
提问by Hiroshi Rana
I have a php code line like below
我有一个像下面这样的 php 代码行
$files = glob('myFolder/*');
I want to use absolute path to myFolder in above by using server document root, like below
我想通过使用服务器文档根目录来使用上面 myFolder 的绝对路径,如下所示
$_SERVER["DOCUMENT_ROOT"]."/myFolder/"
It should be like below
应该像下面这样
$files = glob('$_SERVER["DOCUMENT_ROOT"]."/myFolder/*"');
But this is not working
但这不起作用
How to correct this?
如何纠正这个?
Actually I am trying to do this:
其实我想这样做:
<?php
//Delete All files from folder
// $files = glob('myFolder/*');
$files = glob($_SERVER["DOCUMENT_ROOT"]."/myFolder/*");
foreach($files as $file){
if(is_file($file))
unlink($file);
}
?>
Code below is working
下面的代码正在工作
$files = glob('myFolder/*');
This below is not working
这下面不起作用
$files = glob($_SERVER["DOCUMENT_ROOT"]."/myFolder/*");
I want to use absolute path to myFolder
我想使用 myFolder 的绝对路径
回答by Arkadiusz 'flies' Rzadkowolski
$files = glob($_SERVER["DOCUMENT_ROOT"]."/myFolder/*");
$files = glob($_SERVER["DOCUMENT_ROOT"]."/myFolder/*");

