Jump to content


Photo

Write File Class


  • Please log in to reply
10 replies to this topic

#1 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 09 June 2006 - 06:22 AM

Hi,
I'm setting up a class to read and write to a file. The code I've posted is trimmed to only include the needed code (both the classes and config files are "included" in a broad "main" file)

*Moved code due to Safety script "403"ing...
[a href=\"http://ftp.chrisloveonline.com/config.phps\" target=\"_blank\"]http://ftp.chrisloveonline.com/config.phps[/a]

At this point, when I have it read, it gets nothing.

Help would be appreciated,
Chris
Chris

#2 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 09 June 2006 - 02:39 PM

I've updated the file to include a setFilename() function.

Thanks again,
Chris
Chris

#3 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 02:58 PM

I found your problem but can't post the full solution cos of the security on here. Basically in the read method, where you've got fopen("$this->filename", "r") should be fopen($this -> filename, 'r'). Never put quotes around $this -> anything
[table]



Don't worry, the printer fairies will sort it out.

#4 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 09 June 2006 - 03:05 PM

I've updated the files to include the updates, but still no go.

Anything else you see?

Thanks again,
Chris
Chris

#5 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 03:10 PM

Have you changed:
$contents = fread($handle, filesize("$this->filename"));
to:
$contents = fread($handle, filesize($this -> filename));

Also, the read method doesn't return anything. You need to put
return $contents
at the bottom of it. Then calling $c = $config -> read(); will have whatever $contents is.
[table]



Don't worry, the printer fairies will sort it out.

#6 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 09 June 2006 - 03:38 PM

It reads just fine now, thanks. Now, I need to figure out how to fix the "write" function. It's writing back a blank file.
Chris

#7 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 03:47 PM

Your write method is using a variable $updated_contents but it is not getting that variable from anywhere. You need to either pass the variable to the method when you call it or set a class variable and have the method call that. The former is probably what you're looking for.
[table]



Don't worry, the printer fairies will sort it out.

#8 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 09 June 2006 - 04:04 PM

well, I added a var $updated-contents; in the class

(i'm continuing to update the file in the 1st post)

I also have it returning the postMessage. It is returning a bad, I can't update the file message, but It's still saving as a blank file.

Thanks for you help,
Chris
Chris

#9 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 05:06 PM

just adding var $updated_contents won't help anything. First you need to set the variable either somewhere in the class using $this -> updated_contents = 'blah'; or outside the class using $config -> updated_contents = 'blah'; then in your write method you need to access it using $this -> updated_contents or $uc = $this -> updated_contents

Sorry for the late reply, I got dinner
[table]



Don't worry, the printer fairies will sort it out.

#10 Cell0518

Cell0518
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts
  • LocationUSA / Japan (US Navy)

Posted 09 June 2006 - 05:22 PM

Thanks for your help. I got that last bit sorted out, and it runs great. Thanks again! :D

:SOLVED:


oops, I meant your, not you.... :o
Chris

#11 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 05:27 PM

I'm glad you sorted it out ^_^
[table]



Don't worry, the printer fairies will sort it out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users