RE: [PHP] fwrite() Append Files
| From: | Wei, Alice J. | Date: | Fri, 27 Jun 2008 17:52:42 +0000 |
| Subject: | RE: [PHP] fwrite() Append Files | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-276082@lists.php.net to get a copy of this message | ||
Hi,
Right now I enforced the file to read in through HTTP-Request and output it to a local file.
Looks like this functioned perfectly after I used append functions after I attempted to write to
the file!
Thanks to everyone who contributed to this.
Alice
======================================================
Alice Wei
MIS 2009
School of Library and Information Science
Indiana University Bloomington
ajwei@indiana.edu
________________________________________
From: Jim Lucas [lists@cmsws.com]
Sent: Friday, June 27, 2008 12:45 PM
To: Wei, Alice J.
Cc: Per Jessen; php-general@lists.php.net
Subject: Re: [PHP] fwrite() Append Files
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@indiana.edu
>> ________________________________________
>> From: Per Jessen [per@computer.org]
>> Sent: Friday, June 27, 2008 8:26 AM
>> To: php-general@lists.php.net
>> Subject: Re: [PHP] 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