![]() |
| ||
| fwrite not working with ob_start, Any ideas? Hi, Thanks for checking this out. The error is that when I use ob_start to store the results of an include file my fwrite statement later on in the code works but only writes a blank file, whereas when the ob_start is not present the fwrite function writes the file with all the content present in it. Anyone out there smarter than me about this stuff (not hard) please let me know how to solve this. Thanks.
|
| ||
| Re: fwrite not working with ob_start, Any ideas? You should use fopen with parameter 'a' or 'a+'instead of 'w' in this way if file exists new data will be appended, otherwise php will attemt to create it. http://bg2.php.net/manual/en/function.fopen.php |
| ||
| Re: fwrite not working with ob_start, Any ideas? Ooops...my bad. I thought you want to append content rather than replace it. In this case 'w' is correct option for fopen to be used. Maybe w+, but in any way, as I have read your code more deeply, the fopen function may not be the issue... However, if I am not mistaking, ob_end_clean clears the buffer without output, while ob_get_flush output the buffer as a string. The difference seems to be that end clean simply empties the buffer with no output, while get_flush outputs a string and closes buffering. |
| ||
| Re: fwrite not working with ob_start, Any ideas? i really cannot see how ob_start() would have anything to do with not being able to write to a file. are there any php errors you are getting? also, you are overwriting $to_write at the end of your script, so its not allowing the js to be written to the file. are you doing that on purpose? |
| ||
| Re: fwrite not working with ob_start, Any ideas? Hi Rhyan and kkeith29. Thanks for the replies. kkeith yes I am overwriting $to_write just as a temporary troubleshooting aid. Rhyan I tried changing the code to this (The old code is commented out to let you know whats changed): ob_start(); // start buffer However this doesn't work as the included file is output as content and displayed in the browser window and th ejavascript file is not created. I'm going to try and put the content held int he include file directly in the code and escape every quote I need to and I'll see if that works, but if you have any other ideas please let me know as i really want to keep the content separated and not have to escape everything. Many thanks, Richard EDIT; there are no PHP errors being output either. using the first code is is just a blank page (which is good as I will be using it with a CRON job) or with the modified code the include file is output. |
| ||
| Re: fwrite not working with ob_start, Any ideas? i rewrote the code. see if it works. sometimes you miss the smallest things and rewriting it all over usually solves the problem. i also included a function because repetitive code drives me crazy. <?php |
| ||
| Re: fwrite not working with ob_start, Any ideas? Hey kkeith29, Big thanks for code rewrite but unfortunately it isn't writing the file at all and there are no errors being output. When run it just shows a blank page, then when I check my js_includes folder it doesn't have the file. I haven't tried editing any of the code as I'm sort of out of ideas. I also had a look at what it would take to include the content directly and it isn't nice. I'm stumped. If you've any further ideas please post but if not many thanks for the help so far. Richard |
| ||
| Re: fwrite not working with ob_start, Any ideas? make sure that directory is writable. there is nothing else that would stop it from making that file. |
| ||
| Re: fwrite not working with ob_start, Any ideas? As much as I can tell it is. The file is being written when output buffering is not on. So I would assume that that means that the directory is OK. I'm developing locally on a Mac (the folder properties show it not locked and that read & write is allowed) is there any way that could be causing a problem? If not I'll keep working on it and if I get it I'll make sure to post up the fix. Thanks again for the help. Really appreciate it. Richard |
| ||
| Re: fwrite not working with ob_start, Any ideas? So for anyone who has come across this in the future I wanted to say that i found out the problem and let everyone know. First off thanks for all the help by the guys that posted. So the problem wasn't caused by the output buffering code, rather it was what I was including. In my include file I had other php statements that did some stuff and then output it with echo. What I tried was to use output buffering to create a HTML version of the original include file and then use that (HTML) file in the include statement in the above code samples. That seems to have worked. A bit roundabout but gets the job done. If anyone comes across this in the future and doesn't get what I mean feel free to email rickya100 at g m a i l . c o m. Or if anyone comes across this and thinks OMFG why did he do all that when he could have just [insert stupidly simple code here], feel free to send the better way of doing it to the above email. And I thank you in advance. |
| ||
| Re: fwrite not working with ob_start, Any ideas? Quote:
The only thing I can think of is if you have an error occurring in the output buffering part of the code, and it's stopping code execution from moving on to the file writing portion. Make sure you have error reporting on. ini_set('error_reporting', E_ALL);See if you get errors. ps: a shortcut for: $data = ob_get_contents(); is $data = ob_get_clean(); |
| All times are GMT -4. The time now is 10:29 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC