Enya
Enya

Reputation: 13

How to get local path of a url

$url = 'http://www.site.com/files/file.jpg';

How can I get the local path, like

C:\htdocs\site/files/file.jpg

?

Upvotes: 1

Views: 7229

Answers (4)

Sasho
Sasho

Reputation: 3652

http://blabla.info/somepath/somefile.php

echo $_SERVER["SCRIPT_FILENAME"];

results in [/var/www/htdocs/blabla.info/somepath/somefile.php]

Cheers

Upvotes: 0

SAFAD
SAFAD

Reputation: 784

something as simple as this :

<?php echo __FILE__; ?>

Upvotes: -1

Dan Bizdadea
Dan Bizdadea

Reputation: 1302

You first get the document root of your site with

$_SERVER['DOCUMENT_ROOT'];

And then you append the relative path to your resource Ex:

$_SERVER['DOCUMENT_ROOT'] . '/relative/path/to/files/file.jpg';

Upvotes: 3

Farray
Farray

Reputation: 8528

If you're asking abut getting the local path of a document on a remote server that you don't have access to (other than HTTP), you can't.

If you're trying to get the path of a document on your server, you need an absolute or relative path to the root of the site and then you can derive the full path from there.

Upvotes: 1

Related Questions