Home > Archive > PHP Programming > January 2008 > listing root directory
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
listing root directory
|
|
| Dan Gelder 2008-01-26, 7:08 pm |
| I'm trying to write a script that shows a file picker for my whole web
site. The only part I have left to do is making the script start at
the root directory (my public_html folder). I've messed with
chdir($_SERVER['DOCUMENT_ROOT']) for example but I just can't seem to
get a handle to the top level directory.
Thanks
Dan
| |
| Dan Gelder 2008-01-26, 7:08 pm |
| Never mind the last question, I got it. Now I have another problem:
When i include a php script in another php file, I'd like to put some
img tags inline along with it. The images are in the same file as the
script I'm including. If I get __FILE__ inside my script (which is the
only way I can find to get the actual script file) then how can I
munge the result to turn
/home/.machine/user/site.com/work/january/phpstuff/includer.php
into just
/work/january/phpstuff/
So I can end up with
<img src="http://site.com/work/january/phpstuff/img.jpg"> in the
echo'd result?
I know I can hardcode it but I'd rather not, I'd rather just have it
work.
Thanks
Dan
| |
| Kailash Nadh 2008-01-26, 7:08 pm |
| On Jan 26, 8:25 pm, Dan Gelder <daniel.w.gel...@gmail.com> wrote:
> Never mind the last question, I got it. Now I have another problem:
>
> When i include a php script in another php file, I'd like to put some
> img tags inline along with it. The images are in the same file as the
> script I'm including. If I get __FILE__ inside my script (which is the
> only way I can find to get the actual script file) then how can I
> munge the result to turn
>
> /home/.machine/user/site.com/work/january/phpstuff/includer.php
>
> into just
>
> /work/january/phpstuff/
>
> So I can end up with
>
> <img src="http://site.com/work/january/phpstuff/img.jpg"> in the
> echo'd result?
>
> I know I can hardcode it but I'd rather not, I'd rather just have it
> work.
>
> Thanks
> Dan
$dir = dirname(__FILE__);
--
Kailash Nadh | http://kailashnadh.name
| |
| Dan Gelder 2008-01-26, 10:13 pm |
| On Jan 26, 4:28=A0pm, Kailash Nadh <kailash.n...@gmail.com> wrote:
> On Jan 26, 8:25 pm, Dan Gelder <daniel.w.gel...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> $dir =3D dirname(__FILE__);
>
> --
> Kailash Nadh |http://kailashnadh.name- Hide quoted text -
>
> - Show quoted text -
Thanks for that guess but no, that just turns
/home/.machine/user/site.com/work/january/phpstuff/includer.php
into
/home/.machine/user/site.com/work/january/phpstuff/
and you can read my post to understand why that brings me no closer
than before.
What I need to know, I guess, is a way to get the official root folder
so I have
/home/.machine/user/site.com/
And then I can match the strings?? Can't say how to solve it yet.
| |
| Sebastian Lisken 2008-01-26, 10:13 pm |
| Dan Gelder <daniel.w.gelder@gmail.com> wrote:
> no, that just turns
> /home/.machine/user/site.com/work/january/phpstuff/includer.php
> into
> /home/.machine/user/site.com/work/january/phpstuff/
>
> and you can read my post to understand why that brings me no closer
> than before.
>
> What I need to know, I guess, is a way to get the official root folder
> so I have
> /home/.machine/user/site.com/
>
> And then I can match the strings?? Can't say how to solve it yet.
Wouldn't $_SERVER["SCRIPT_NAME"] do what you are looking for? Don't use
$_SERVER["PHP_SELF"] because that can contain so-called "additional path
information" that users could be adding to the script's URL in some
circumstances (/january/phpstuff/includer.php/extra/stuff) and which,
incidentally, makes $_SERVER["PHP_SELF"] a value that should not be
trusted. Mind you, perhaps it's better to regard all of $SERVER as
untrusted just to err on the side of caution.
Sebastian Lisken
| |
| Dan Gelder 2008-01-26, 10:13 pm |
| On Jan 26, 8:46=A0pm, Sebastian Lisken <Sebastian.Lis...@Uni-Bielefeld-
deletethis.de> wrote:
> Dan Gelder =A0<daniel.w.gel...@gmail.com> wrote:
>
>
>
>
>
> Wouldn't $_SERVER["SCRIPT_NAME"] do what you are looking for? Don't use
> $_SERVER["PHP_SELF"] because that can contain so-called "additional path
> information" that users could be adding to the script's URL in some
> circumstances (/january/phpstuff/includer.php/extra/stuff) and which,
> incidentally, makes $_SERVER["PHP_SELF"] a value that should not be
> trusted. Mind you, perhaps it's better to regard all of $SERVER as
> untrusted just to err on the side of caution.
>
> Sebastian Lisken
I know not to trust $_SERVER too far, but it doesn't matter, because I
am interested in finding the *included file*'s location, not the base
script. IE:
------
------ folder1/file1.php:
------
echo "Here is an image from another folder:";
include '/folder2/file2.php';
------
------ folder2/file2.php:
------
function getGlobalPrefix()
{
//this is what I need to write:
//it takes the data in __FILE__ and somehow turns that into 'http://
mySite.com/folder2/'
}
echo "<img src=3D'" . getGlobalPrefix() . "/myGreatImage.gif'>";
------
OK, does it make sense now?? :-)
Dan
| |
| AnrDaemon 2008-01-27, 7:18 pm |
| Greetings, Dan Gelder.
In reply to Your message dated Sunday, January 27, 2008, 05:08:15,
[color=darkred]
> I know not to trust $_SERVER too far, but it doesn't matter, because I
> am interested in finding the *included file*'s location, not the base
> script. IE:
> ------
> ------ folder1/file1.php:
> ------
> echo "Here is an image from another folder:";
> include '/folder2/file2.php';
> ------
> ------ folder2/file2.php:
> ------
> function getGlobalPrefix()
> {
> //this is what I need to write:
> //it takes the data in __FILE__ and somehow turns that into 'http://
> mySite.com/folder2/'
> }
> echo "<img src='" . getGlobalPrefix() . "/myGreatImage.gif'>";
> ------
> OK, does it make sense now?? :-)
You has an advice but don't get it right.
$dir = dirname(__FILE__); // current script location
if(stripos($_SERVER['DOCUMENT_ROOT'], $dir) === 0)
{
$dir = substr($dir, strlen($_SERVER['DOCUMENT_ROOT']));
echo("<img src=\"{$dir}/image_in_the_same_location_as_script\"/>");
}
--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>
|
|
|
|
|