Re: [PHP] writting to files

2002-05-31 Thread Jason Wong

On Saturday 01 June 2002 04:34, Jas wrote:
> Ok, I have been working on this for awhile and cannot seem to get the
> fwrite function to work.  Here is the code:
> \\ index.php
>  $file_name = 'blank.php';
> $open_file = fopen("$file_name","rw");

Looks like you're using fopen() incorrectly. Try:

  fopen("$file_name","r+");

> if (!$passwords) {
>  header ("Location: index.php");
>  } else {
>  $file_name= "blank.php";
>  $file_open = fopen($file_name, "rw");

Ditto.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Egotist:  A person of low taste, more interested in himself than in me.
-- Ambrose Bierce
*/


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




[PHP] writting to files

2002-05-31 Thread Jas

Ok, I have been working on this for awhile and cannot seem to get the fwrite
function to work.  Here is the code:
\\ index.php


  
  
  

This works as I need it to, opens the file and then removes the first < so
that it won't be parsed as a php script.
\\ edit_passwords.php

I have read and write permissions set on the file and the directory.  It
will not write changes to the file.  Any pointers?
Jas



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




Re: [PHP] Writting to files.?

2001-07-05 Thread James Bartlett

Thanks for the response so far...

I'm still not sure on how to get the code to start on a new line in the file (yes they 
are text files). Say I wrote variable1 to line one how do I get it to write the next 
variable to line two?

Thanks
  - Original Message - 
  From: Don Read 
  To: James Bartlett 
  Cc: [EMAIL PROTECTED] 
  Sent: Thursday, July 05, 2001 6:40 PM
  Subject: RE: [PHP] Writting to files.?



  On 05-Jul-01 James Bartlett wrote:
  > Hi,
  > 
  > Anyone know how I can write and read to different lines in a file rather
  > than just adding to the text already on the first line of the file?
  > 
  > Thanks
  > 

  Assuming you're talking about text files:

  A. suck the whole thing up in memory, change it there, write it back out.
  B. open a temp, copy till the line of interest, write your change,
 copy remainder. mv/cp the temp to the original.
  C. read to line of interest, ftell(), suck remainder into memory.
 ftruncate(), fseek(), write your changes, write out the remainder.

  Regards, 
  -- 
  Don Read   [EMAIL PROTECTED]
  -- It's always darkest before the dawn. So if you are going to 
 steal the neighbor's newspaper, that's the time to do it.



RE: [PHP] Writting to files.?

2001-07-05 Thread lists

On Thu, 5 Jul 2001, Don Read wrote:

> > Anyone know how I can write and read to different lines in a file rather
> > than just adding to the text already on the first line of the file?
>
> A. suck the whole thing up in memory, change it there, write it back out.

Just as a note: for large (text or binary) files, it's better to use a
temporary file (see tmpfile()) and limit the in-memory buffer to smth like
1024. After finishing, do not close the tmpfile (this would automatically
delete it), but lseek and copy back to the original. Anyone know any
better ways to deal with large file contents?

thx,
georgeb


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




RE: [PHP] Writting to files.?

2001-07-05 Thread Don Read


On 05-Jul-01 James Bartlett wrote:
> Hi,
> 
> Anyone know how I can write and read to different lines in a file rather
> than just adding to the text already on the first line of the file?
> 
> Thanks
> 

Assuming you're talking about text files:

A. suck the whole thing up in memory, change it there, write it back out.
B. open a temp, copy till the line of interest, write your change,
   copy remainder. mv/cp the temp to the original.
C. read to line of interest, ftell(), suck remainder into memory.
   ftruncate(), fseek(), write your changes, write out the remainder.

Regards, 
-- 
Don Read   [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

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




[PHP] Writting to files.?

2001-07-05 Thread James Bartlett

Hi,

Anyone know how I can write and read to different lines in a file rather than just 
adding to the text already on the first line of the file?

Thanks

Zotud