Jump to content

Archived

This topic is now archived and is closed to further replies.

Cell0518

Write File Class

Recommended Posts

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

Share this post


Link to post
Share on other sites
I've updated the file to include a setFilename() function.

Thanks again,
Chris

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
I've updated the files to include the updates, but still no go.

Anything else you see?

Thanks again,
Chris

Share this post


Link to post
Share on other sites
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 [code]return $contents[/code] at the bottom of it. Then calling $c = $config -> read(); will have whatever $contents is.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.