Re: fwrite() Append Files

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

 



Jim Lucas wrote:
Wei, Alice J. wrote:
Hi,

This is my current code:

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

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


You are referring to the file from the website point of view.

You must access it from the filesystem point of view

$file = '/path/to/public_html/hello.txt';





   $ourFileName = "hello.txt";

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

   fclose($ourFileHandle);

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


Same thing here. You are never going to be able to write to that file. The webserver will never allow it.


I guess I should have suggested a work around in this case.

You will need to create the file locally and then transfer via ftp/scp/etc... the newly created file to the remote server.

I built an FTP client once with PHP using the built in FTP functions. You will probably need to do something similar.




   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






--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
       and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare


--
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