problem trying to detect what folder a file resides in

This is a discussion on problem trying to detect what folder a file resides in within the PHP Language forums, part of the PHP Programming Forums category; I am trying to auto-detect what folder a file is sitting in and based upon this info, query a ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-30-2003
Marcus
 
Posts: n/a
Default problem trying to detect what folder a file resides in

I am trying to auto-detect what folder a file is sitting in and based
upon this info, query a MySQL database to get further information. I
have been all over php.net and been through numerous examples, but I
can't get my script to do exactly what I want...

An example given on php.net regarding dirname() is as follows:


dirname can be used to create self referencing web scripts with the
following one liner.

$base_url = str_replace($DOCUMENT_ROOT, "", dirname($PHP_SELF));

Using this method on a file such as:

/home/mysite/public_html/wherever/whatever.php

will return:

/wherever


This code could very well be right, but it's not working on my localhost
or on my live server... instead of returning only the folder in
question, it returns the full path to the file. Going with the above
example, if "home" were specified as the server, it would return
/mysite/public_html/wherever instead of simply "wherever". I have also
tried echoing $DOCUMENT_ROOT and $PHP_SELF to see exactly what I have to
work with and trying to manipulate these values, but I can't seem to
make it work with other methods I have tried either. Thanks very much
in advance for any help anyone can provide.

Marcus

Reply With Quote
  #2 (permalink)  
Old 06-30-2003
sotto
 
Posts: n/a
Default Re: problem trying to detect what folder a file resides in

On Mon, 30 Jun 2003 02:08:15 -0500, Marcus wrote:

> I am trying to auto-detect what folder a file is sitting in and based upon
> this info, query a MySQL database to get further information. I have been
> all over php.net and been through numerous examples, but I can't get my
> script to do exactly what I want...
>
> An example given on php.net regarding dirname() is as follows:
>
>
> dirname can be used to create self referencing web scripts with the
> following one liner.
>
> $base_url = str_replace($DOCUMENT_ROOT, "", dirname($PHP_SELF));
>
> Using this method on a file such as:
>
> /home/mysite/public_html/wherever/whatever.php
>
> will return:
>
> /wherever
>
>
> This code could very well be right, but it's not working on my localhost
> or on my live server... instead of returning only the folder in question,
> it returns the full path to the file. Going with the above example, if
> "home" were specified as the server, it would return
> /mysite/public_html/wherever instead of simply "wherever". I have also
> tried echoing $DOCUMENT_ROOT and $PHP_SELF to see exactly what I have to
> work with and trying to manipulate these values, but I can't seem to make
> it work with other methods I have tried either. Thanks very much in
> advance for any help anyone can provide.
>
> Marcus

Have you tried setting
$DOCUMENT_ROOT = "/home/mysite/public_html"
before that bit of code you have?
Then it will change /home/mysite/public_html/ with nothing, so you'd have
/wherever in this example, but when trying on a file like
/home/mysite/public_html/wherever/whatever/myfile.php you'd get
/wherever/whatever

If you'd only want /whatever in that case, you could use some
stringfunctions to cut of everyting before the last / then you'd have
/whatever

.... hope this helps
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:29 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0