Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Document Root Path in PHP [closed]

Tags:

I have a php code line like below

$files = glob('myFolder/*'); 

I want to use absolute path to myFolder in above by using server document root, like below

$_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

like image 444
Hiroshi Rana Avatar asked Mar 04 '13 21:03

Hiroshi Rana


People also ask

Where is my PHP document root?

php //PHP Script to find Document Root of Application $docroot = getenv("DOCUMENT_ROOT"); echo $docroot; ?> As per above PHP script actual DOCUMENT ROOT of application will be stored in $docroot variable which can be used further in application.

What is $_ SERVER [' DOCUMENT_ROOT ']?

$_SERVER['DOCUMENT_ROOT'] returns. The document root directory under which the current script is executing, as defined in the server's configuration file.

How do I change the root path in PHP?

You can change this permanently by hacking internal Finder options (Google for details), or more simply to make an occasional change, just use the "Go > Go to folder" menu option which will let you open hidden folders directly by name.

What is stored in the document root and SERVER root folders of a Web server?

The document root is the folder where the website files for a domain name are stored. Since cPanel allows for multiple domain names (addon domains and subdomains), you need to have a unique folder for each domain.


1 Answers

$files = glob($_SERVER["DOCUMENT_ROOT"]."/myFolder/*");

like image 72
Arkadiusz 'flies' Rzadkowolski Avatar answered Sep 27 '22 21:09

Arkadiusz 'flies' Rzadkowolski