Jump to content


define a path


5 replies to this topic

#1 b00g3R

    Young Padawan

  • Members
  • Pip
  • 81 posts
  • Gender:Male
  • Location:Chicago, IL, USA

Posted 13 August 2006 - 06:25 PM

Ok, So I was doing this tutorial that is a simple directory listing.. here is the code

<?

//define the path as relative
$path = "/home/yoursite/public_html/whatever";

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

echo "Directory Listing of $path<br/>";

//running the while loop
while ($file = readdir($dir_handle)) 
{
   echo "<a href='$file'>$file</a><br/>";
}

//closing the directory
closedir($dir_handle);

?>

my thing is tho.. since i just have a web host how do i define my path? like say if its a folder that is outside of the folder i have this file in..


ps. i hate being a newB

Edited by b00g3R, 13 August 2006 - 07:21 PM.


#2 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

Posted 13 August 2006 - 08:04 PM

directories 101!

you would use ../ to go higher one level (../../ to go two levels higher, etc), or use blah/blah/blah/ to go into sub folders

so change $path = "/home/yoursite/public_html/whatever"; to whatever you want it to be

#3 b00g3R

    Young Padawan

  • Members
  • Pip
  • 81 posts
  • Gender:Male
  • Location:Chicago, IL, USA

Posted 13 August 2006 - 08:15 PM

is there a way you can display what ur full path was to the file?


ps

i know i can move that but i was just asking about some times if you want to go into a folder that is a subfolder you have have to put the whole thing...

ex. /user/username/home/public_html/whatever
maybe that is for linux boxs only.. idono

ps. i hate being a newB

#4 danieldaniel

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male
  • Location:Columbus, Ohio
  • Interests:Skateboarding, Macs, BMX, Cocoa, PHP, CSS etc.

Posted 14 August 2006 - 12:46 AM

If you mean what I think you mean, this should work:
<?
echo $_SERVER['DOCUMENT_ROOT'];
?>

If not, then I have no clue what you mean.

Edited by danieldaniel, 14 August 2006 - 12:49 AM.


#5 b00g3R

    Young Padawan

  • Members
  • Pip
  • 81 posts
  • Gender:Male
  • Location:Chicago, IL, USA

Posted 14 August 2006 - 01:16 AM

WoW!

How Dumb!
I didn't even think about that. And I remember reading about that!

Thx


ps. i def. hate being a newB


Edit:

Also this works 2
<? print $PATH_TRANSLATED; ?>

Edited by b00g3R, 14 August 2006 - 01:22 AM.


#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 14 August 2006 - 02:21 AM

don't use $PATH_TRANSLATED, it's not secure. Turn register_globals off (google it, trust me), and use $_SERVER['PATH_TRANSLATED']. Actually, $_SERVER['DOCUMENT_ROOT'] is probably more ideal, as i believe it's defined on all servers (one of those two is semi-optional).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users