Cell0518 Posted June 9, 2006 Share Posted June 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/ Share on other sites More sharing options...
Cell0518 Posted June 9, 2006 Author Share Posted June 9, 2006 I've updated the file to include a setFilename() function.Thanks again,Chris Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43642 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43651 Share on other sites More sharing options...
Cell0518 Posted June 9, 2006 Author Share Posted June 9, 2006 I've updated the files to include the updates, but still no go.Anything else you see?Thanks again,Chris Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43656 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43660 Share on other sites More sharing options...
Cell0518 Posted June 9, 2006 Author Share Posted June 9, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43684 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43689 Share on other sites More sharing options...
Cell0518 Posted June 9, 2006 Author Share Posted June 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43700 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 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_contentsSorry for the late reply, I got dinner Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43738 Share on other sites More sharing options...
Cell0518 Posted June 9, 2006 Author Share Posted June 9, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43746 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 I'm glad you sorted it out ^_^ Quote Link to comment https://forums.phpfreaks.com/topic/11558-write-file-class/#findComment-43750 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.