Hi, I need help with the server location my file path for the text file order.txt.

according to my php text book, this is what they say I should use:

@  $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'rb'); 

however, this didn't work the server doesn't recognize where the file is located.
This line below me is the absolute path and it works so I want to know if there is something wrong with the first method

@  $fp = fopen("c:\Program Files\Apache software Foundation\Apache2.2\htdocs\orders\orders.txt", 'rb');

This is the code:

<?php
  //create short variable name
  $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
  <title>Bob's Auto Parts - Customer Orders</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Customer Orders</h2>
<?php

@  $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'rb');

   if (!$fp)
   {
     echo '<p><strong>No orders pending.'
         .'Please try again later.</strong></p>';
     exit;
   }

   while (!feof($fp))
   {
      $order= fgets($fp, 999);
      echo $order.'<br />';
   }

echo 'Final position of the file pointer is '.(ftell($fp));
echo '<br />';
rewind($fp);
echo 'After rewind, the position is '.(ftell($fp));
echo '<br />';


   fclose($fp);

?>
</body>
</html>

Recommended Answers

All 3 Replies

why are you using the ../ folder. this means move up one directory. since you are finding the file from the root this is uneccessary.

i guess after thinking about it, the file could be in a folder that is above the root directory.

in that case, what is your root directory?

why are you using the ../ folder. this means move up one directory. since you are finding the file from the root this is uneccessary.

i guess after thinking about it, the file could be in a folder that is above the root directory.

in that case, what is your root directory?

Hi, thanks alot for replying. If you are asking for root directory I guess it would be c:// ?

just echo out $DOCUMENT_ROOT or $_SERVER and tell me what is returned.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.