2am dumb question, Finding a location out of root

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

2am dumb question, Finding a location out of root

Post by aybra »

hello.. i know this is extremely dumb question... but using a Reactor type server on my home network, how do i point to / add lines to a file out side of the "root"??


Code: Select all

$filename = 'C:\Program Files\Sony\EverQuest II\logseq2.txt';
$somecontent = "Add this to the file\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence 
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   
   echo "Success, wrote ($somecontent) to file ($filename)";
   
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Not entirely sure what you're asking.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post by aybra »

sorry,

To get to a location above the directory you are working in. ../ or some form is used to get all the way up to root... but i want to go past that and go to a differant location on my hard drive... how do i get there?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

realpath();
aybra
Forum Commoner
Posts: 56
Joined: Sun Nov 24, 2002 12:52 am

Post by aybra »

Thank you!!
Post Reply