Satch3000
Satch3000

Reputation: 49384

PHP display current server path

I need to setup a path in my php but I currently don't know the path.

I need to configure the paths to the uploads directory

Should look like this below:

/srv/www/uploads/

My uploads.php file is in the root...so

www/uploads/ ???

Is there anyway that I could get php to tell me my current path?

Upvotes: 39

Views: 192564

Answers (5)

Eusebius
Eusebius

Reputation: 531

  • To get your current working directory: getcwd() (documentation)
  • To get the document root directory: $_SERVER['DOCUMENT_ROOT'] (documentation)
  • To get the filename of the current script: $_SERVER['SCRIPT_FILENAME']

Upvotes: 17

David
David

Reputation: 51

You can also use the following alternative realpath.

Create a file called path.php

Put the following code inside by specifying the name of the created file.

<?php 
    echo realpath('path.php'); 
?>

A php file that you can move to all your folders to always have the absolute path from where the executed file is located.

;-)

Upvotes: 5

Gregory R.
Gregory R.

Reputation: 1935

echo $_SERVER["DOCUMENT_ROOT"];

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

http://php.net/manual/en/reserved.variables.server.php

Upvotes: 18

Johnzo
Johnzo

Reputation: 112

php can call command line operations so

echo exec("pwd");

Upvotes: 2

Nick
Nick

Reputation: 6346

If you call getcwd it should give you the path:

<?php
  echo getcwd();
?>

Upvotes: 81

Related Questions