Hello all,

Please bear with me for a moment.  I am new to PHP work, but have over 10
years experience in various other programming languages including C/C++

I'm just getting really frustrated here, and i'm hoping its a simple
mistake.  What I am running into is that ever file I open and read from, I
never actually get any data.  I know the data is in the file, but I don't
get it.  I can write to it fine.

Basic scenario is this...I have 2 modules, one that creates my data and one
that reads it.  I'm setting up a system for book reviews.  The first module
has a forms page that gets the book's ASIN, TITLE, and DESCRIPTION.  There
is a common books directory.  The module creates a subdirectory off of this
dir, and the sub dir's name is the ASIN of the book.  In this new sub
directory a file is created that contains 3 lines.  The ASIN, the TITLE, and
the DESCRIPTION, each seperated by a newline (\n).  This seems to work fine.

The second module is one that will display everythign to the users, and
eventually allow user submitted reviews.  This module opens a directory
handle for the common books directory, and enumerates each subdir (skipping
'.' and '..').  It then attempts to open the information file in each subdir
that was created above, and display the results.  Its always empty.  I can
include code if requested, but here are a few snippets of the immediate
areas..

first module 1 which does the saving of info:

 case 'save_info':
  if ($book_file = fopen("$booksdir/books.dat", "a"))
  {
   fwrite($book_file, $asin);
  }
  fclose($book_file);
  if ($book_file = fopen("$thisdir/book_info.dat", "w"))
  {
   fwrite($book_file, "$asin\n$title\n$description");
  }
  fclose($book_file);
  break;


and the module 2, the reads:
 // get directory handle
 $dir_handle = opendir($thisdir);
 $books = array();
 // load valid book directories into an array
 while($book_file = readdir($dir_handle))
 {
  if ($book_file != "." && $book_file != ".." &&
is_dir("$thisdir/$book_file"))
  {
   $books[] = $book_file;
   echo "<p>Added: $book_file";
  }
 }
 // loop through books and create HTML entry for each
 $index = 0;
 for ($index = 0; $index < sizeof($books); $index++)
 {
  $book_data_file = fopen("$thisdir/$books[$index]/book_info.dat", "r");
  echo "<p>Opened $thisdir/$books[$index]/book_info.dat</p>";
  $book_data_in = fread($book_data_file, filesize($book_data_file));
  echo "<p>book_data_in = $book_data_in</p>";
  fclose($book_data_file);
  $book_data = explode("\n", $book_data_in);
  echo "ASIN:";
  echo "$book_data[0]";
  echo "<br>";
  echo "Title:";
  echo "$book_data[1]";
  echo "<br>";
  echo "Description:";
  echo "$book_data[2]";
  echo "<p></p>";
 }


If anyoen can clear this up for me, I would most appreciate it.  I'm on a
tight deadline, learning PHP as I go, and losing my mind on this seemingly
simple excersise!

- John Vanderbeck
- Admin, GameDesign


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to