RE: fwrite() Append Files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

This is my current code:

   $lines = file("http://www.mysite.com/hello.txt";);

   $file="http://www.mysite.com/hello.txt";;



   $ourFileName = "hello.txt";

   $ourFileHandle = fopen($ourFileName, 'wb') or die("can't open file");

   fclose($ourFileHandle);

   $newFileName="http://www.yoursite.com/hello.txt";;



   echo $newFileName;

   $result=rename($ourFileName, $newFileName);

   $ourFileHandle = fopen($ourFileName, 'wb') or die("can't open file");



// Loop through our array, show HTML source as HTML source; and line numbers too.



  foreach ($lines as $line_num => $line) {



      echo "<p>Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "</p>";

      $ourFileHandle = fopen($newFileName, 'wb') or die("can't open file");

      $content=fwrite($ourFileHandle, htmlspecialchars($line));

      echo "<p>The line: $content has been written into $newFilename</p>";

}

fclose($ourFileHandle);

Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')?

What I really wanted to do is to copy the file directory from $file to $newFileName directory using the cp command or something, but if I cannot do that, writing in and out of the file may be good enough.

Alice
======================================================
Alice Wei
MIS 2009
School of Library and Information Science
Indiana University Bloomington
ajwei@xxxxxxxxxxx
________________________________________
From: Per Jessen [per@xxxxxxxxxxxx]
Sent: Friday, June 27, 2008 8:26 AM
To: php-general@xxxxxxxxxxxxx
Subject: Re:  fwrite() Append Files

Wei, Alice J. wrote:

> Hi,
>
>   I wonder if anyone on the list could tell me how to append the files
>   as I am writing in them. I have a file that has no more than five
>   characters per line, and I would like to keep its spacing between
>   the lines. Right now I have the set up so that it could write in the
>   first line, but the problem is that all the lines after it never get
>   written in to the desired file.

You need to open the file in append mode = 'a+'.


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux