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($DO CUMENT_ROOT, "", dirname($PHP_SE LF));
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
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($DO CUMENT_ROOT, "", dirname($PHP_SE LF));
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
Comment