[PHP] Fwrite() vs file_put_contents()
I have been pondering whether it would be feasible to work with a 100,000 entry index file, and had put yesterday aside to do some timing tests. I first generated some sample index files of various lengths. Each entry consisted of a single line with the form ASDF;rhubarb, rhubarb, where the ASDF is a randomly generated four character index, and the rest of the line is filling, which varies slightly in length and contents from line to line, just in case something tried to get smart and cache the line. The average lenth of the line is about 80 bytes. Then I wrote another program which read the file into an array, using the four character index as the key, and the filling as the contents, sorted the array, and then rewrote it to another file, reporting the elapsed time after each step. My first version used fgets() to read the source file a line at a time, and fwrite() to write the new file. This version performed quite consistently, and took approximately 1.3 seconds to read in a 100,000 entry 7.86Mb file, and another 5 seconds to write it out again. I then read the discussion following fschnittke's post File write operation slows to a crawl ... and wondered if the suggestions made there would help. First I used file() to read the entire file into memory, then processed each line into the form required to set up my matrix. This gave a useful improvement for small files, halving the time required to read and process a 10,000 entry 815 kB file, but for a 30,000 entry file it had dropped to about 15%, and it made little difference for a 300,000 entry file. Then I tried writing my whole array into a single horrendous string, and using file_put_contents() to write out the whole string in one bang. I started testing on a short file, and thought I was onto a good thing, as it halved the time to write out a 10,000 entry 800 K file. But as I increased the file size it began to fail dismally. With a 30,000 entry file it was 20% slower, and at 100,000 entries it was three times slower. On Shawn McKenzie's suggestion, I also tried replacing fgets() with stream_get_line(). As I had anticipated any difference was well within below the timing noise level. In conclusion, for short (1MB!) files, using file() to read the whole file into memory is substantially better than using fgets() to read the file a line at a time, but the advantage rapidly diminishes for longer files. Similarly using file_put_contents() in place of fwrite() to write it out again is better for short files (up to perhaps 1 MB) but the performance deteriorates rapidly above this. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite() Append Files
Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. Is there some sort of command that I could use to append files as I am writing them? I would provide the code if this is not clear enough. Thanks in advance. Alice == Alice Wei MIS 2009 School of Library and Information Science Indiana University Bloomington [EMAIL PROTECTED]
FW: [PHP] fwrite() Append Files
Please post the code, I'm not clear on the problem. -Original Message- From: Wei, Alice J. [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 12:02 PM To: php-general@lists.php.net Subject: [PHP] fwrite() Append Files Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. Is there some sort of command that I could use to append files as I am writing them? I would provide the code if this is not clear enough. Thanks in advance. Alice == Alice Wei MIS 2009 School of Library and Information Science Indiana University Bloomington [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: FW: [PHP] fwrite() Append Files
Hey Alice, Are you sure you can do this with vanilla flavor PHP ? Your professor could be mistaking on this particular assignment. Maybe some kind of webservice could do the trick. ASP.net is really good at handling file I/O. Kind regards, Stijn Chris Scott wrote: Please post the code, I'm not clear on the problem. -Original Message- From: Wei, Alice J. [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 12:02 PM To: php-general@lists.php.net Subject: [PHP] fwrite() Append Files Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. Is there some sort of command that I could use to append files as I am writing them? I would provide the code if this is not clear enough. Thanks in advance. Alice == Alice Wei MIS 2009 School of Library and Information Science Indiana University Bloomington [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() Append Files
Wei, Alice J. wrote: Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. Is there some sort of command that I could use to append files as I am writing them? I would provide the code if this is not clear enough. Thanks in advance. Alice Alice, ALWAYS POST CODE. It gives us an example that you have done your assignment to begin with and aren't continuing to ask this list to do your work for you. RTFM as the fwrite module is pretty clear on its usage. But start with posting your current code (and not pseudo code) so that we can point you in a better direction. Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() Append Files
Wei, Alice J. wrote: Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. You need to open the file in append mode = 'a+'. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] fwrite() Append Files
Hi, This is my current code: $lines = file(http://www.mysite.com/hello.txt;); $file=http://www.mysite.com/hello.txt;; $ourFileName = hello.txt; $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); fclose($ourFileHandle); $newFileName=http://www.yoursite.com/hello.txt;; echo $newFileName; $result=rename($ourFileName, $newFileName); $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num = $line) { echo pLine #b{$line_num}/b : . htmlspecialchars($line) . /p; $ourFileHandle = fopen($newFileName, 'wb') or die(can't open file); $content=fwrite($ourFileHandle, htmlspecialchars($line)); echo pThe line: $content has been written into $newFilename/p; } fclose($ourFileHandle); Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? What I really wanted to do is to copy the file directory from $file to $newFileName directory using the cp command or something, but if I cannot do that, writing in and out of the file may be good enough. Alice == Alice Wei MIS 2009 School of Library and Information Science Indiana University Bloomington [EMAIL PROTECTED] From: Per Jessen [EMAIL PROTECTED] Sent: Friday, June 27, 2008 8:26 AM To: php-general@lists.php.net Subject: Re: [PHP] fwrite() Append Files Wei, Alice J. wrote: Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. You need to open the file in append mode = 'a+'. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] fwrite() Append Files
Wei, Alice J. wrote: Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? I think fopen($ourFileName, 'a') will do what you want. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() Append Files
On Fri, Jun 27, 2008 at 7:01 AM, Wei, Alice J. [EMAIL PROTECTED] wrote: Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. Is there some sort of command that I could use to append files as I am writing them? I would provide the code if this is not clear enough. This is generally your first stop when you have a question, meaning you don't read the manual, right? There are a few file-writing tools included in a basic PHP build. Always RTFM before posting here. http://php.net/file-put-contents http://php.net/fwrite -- /Daniel P. Brown Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just $59.99/mo. with no contract! Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] FW: [SPAM] RE: [PHP] fwrite() Append Files
I don't think you can open files for writing over http, you get an error: failed to open stream: HTTP wrapper does not support writeable connections. -Original Message- From: Per Jessen [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 2:39 PM To: php-general@lists.php.net Subject: [SPAM] RE: [PHP] fwrite() Append Files Importance: Low Wei, Alice J. wrote: Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? I think fopen($ourFileName, 'a') will do what you want. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] FW: [SPAM] RE: [PHP] fwrite() Append Files
-Original Message- From: Chris Scott [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 8:48 AM To: php-general@lists.php.net Subject: [PHP] FW: [SPAM] RE: [PHP] fwrite() Append Files Importance: Low I don't think you can open files for writing over http, you get an error: failed to open stream: HTTP wrapper does not support writeable connections. -Original Message- From: Per Jessen [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 2:39 PM To: php-general@lists.php.net Subject: [SPAM] RE: [PHP] fwrite() Append Files Importance: Low Wei, Alice J. wrote: Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? I think fopen($ourFileName, 'a') will do what you want. From Alice's code: $ourFileName = hello.txt; $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); So... she is not, in fact, trying to write a file over HTTP. She is reading a file via HTTP and writing something pertaining to it on the local file system. Also, please refrain from top-posting. It makes the posts get very confusing. :( Todd Boyd Web Programmer
[PHP] FW: [SPAM] RE: [PHP] FW: [SPAM] RE: [PHP] fwrite() Append Files
-Original Message- From: Chris Scott [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 8:48 AM To: php-general@lists.php.net Subject: [PHP] FW: [SPAM] RE: [PHP] fwrite() Append Files Importance: Low I don't think you can open files for writing over http, you get an error: failed to open stream: HTTP wrapper does not support writeable connections. -Original Message- From: Per Jessen [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 2:39 PM To: php-general@lists.php.net Subject: [SPAM] RE: [PHP] fwrite() Append Files Importance: Low Wei, Alice J. wrote: Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? I think fopen($ourFileName, 'a') will do what you want. From Alice's code: $ourFileName = hello.txt; $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); So... she is not, in fact, trying to write a file over HTTP. She is reading a file via HTTP and writing something pertaining to it on the local file system. Also, please refrain from top-posting. It makes the posts get very confusing. :( Todd Boyd Web Programmer Sorry about the top posting, just habit. I'll stop doing it. From Alice's code: $newFileName=http://www.yoursite.com/hello.txt;; echo $newFileName; $result=rename($ourFileName, $newFileName); $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num = $line) { echo pLine #b{$line_num}/b : . htmlspecialchars($line) . /p; $ourFileHandle = fopen($newFileName, 'wb') or die(can't open file); $content=fwrite($ourFileHandle, htmlspecialchars($line)); .. The fwrite is $ourFileHandle which on the previous line is set to $newFileName which is http://www.yoursite.com/hello.txt. I might have missed the point (I regularly do) but it looks like http to me.
Re: [PHP] fwrite() Append Files
Wei, Alice J. wrote: Hi, This is my current code: $lines = file(http://www.mysite.com/hello.txt;); $file=http://www.mysite.com/hello.txt;; You are referring to the file from the website point of view. You must access it from the filesystem point of view $file = '/path/to/public_html/hello.txt'; $ourFileName = hello.txt; $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); fclose($ourFileHandle); $newFileName=http://www.yoursite.com/hello.txt;; Same thing here. You are never going to be able to write to that file. The webserver will never allow it. echo $newFileName; $result=rename($ourFileName, $newFileName); $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num = $line) { echo pLine #b{$line_num}/b : . htmlspecialchars($line) . /p; $ourFileHandle = fopen($newFileName, 'wb') or die(can't open file); $content=fwrite($ourFileHandle, htmlspecialchars($line)); echo pThe line: $content has been written into $newFilename/p; } fclose($ourFileHandle); Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? What I really wanted to do is to copy the file directory from $file to $newFileName directory using the cp command or something, but if I cannot do that, writing in and out of the file may be good enough. Alice == Alice Wei MIS 2009 School of Library and Information Science Indiana University Bloomington [EMAIL PROTECTED] From: Per Jessen [EMAIL PROTECTED] Sent: Friday, June 27, 2008 8:26 AM To: php-general@lists.php.net Subject: Re: [PHP] fwrite() Append Files Wei, Alice J. wrote: Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. You need to open the file in append mode = 'a+'. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() Append Files
Jim Lucas wrote: Wei, Alice J. wrote: Hi, This is my current code: $lines = file(http://www.mysite.com/hello.txt;); $file=http://www.mysite.com/hello.txt;; You are referring to the file from the website point of view. You must access it from the filesystem point of view $file = '/path/to/public_html/hello.txt'; $ourFileName = hello.txt; $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); fclose($ourFileHandle); $newFileName=http://www.yoursite.com/hello.txt;; Same thing here. You are never going to be able to write to that file. The webserver will never allow it. I guess I should have suggested a work around in this case. You will need to create the file locally and then transfer via ftp/scp/etc... the newly created file to the remote server. I built an FTP client once with PHP using the built in FTP functions. You will probably need to do something similar. echo $newFileName; $result=rename($ourFileName, $newFileName); $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num = $line) { echo pLine #b{$line_num}/b : . htmlspecialchars($line) . /p; $ourFileHandle = fopen($newFileName, 'wb') or die(can't open file); $content=fwrite($ourFileHandle, htmlspecialchars($line)); echo pThe line: $content has been written into $newFilename/p; } fclose($ourFileHandle); Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? What I really wanted to do is to copy the file directory from $file to $newFileName directory using the cp command or something, but if I cannot do that, writing in and out of the file may be good enough. Alice == Alice Wei MIS 2009 School of Library and Information Science Indiana University Bloomington [EMAIL PROTECTED] From: Per Jessen [EMAIL PROTECTED] Sent: Friday, June 27, 2008 8:26 AM To: php-general@lists.php.net Subject: Re: [PHP] fwrite() Append Files Wei, Alice J. wrote: Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. You need to open the file in append mode = 'a+'. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] FW: [SPAM] RE: [PHP] fwrite() Append Files
Boyd, Todd M. wrote: -Original Message- From: Chris Scott [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 8:48 AM To: php-general@lists.php.net Subject: [PHP] FW: [SPAM] RE: [PHP] fwrite() Append Files Importance: Low I don't think you can open files for writing over http, you get an error: failed to open stream: HTTP wrapper does not support writeable connections. -Original Message- From: Per Jessen [mailto:[EMAIL PROTECTED] Sent: Friday, June 27, 2008 2:39 PM To: php-general@lists.php.net Subject: [SPAM] RE: [PHP] fwrite() Append Files Importance: Low Wei, Alice J. wrote: Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? I think fopen($ourFileName, 'a') will do what you want. From Alice's code: $ourFileName = hello.txt; $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); So... she is not, in fact, trying to write a file over HTTP. She is reading a file via HTTP and writing something pertaining to it on the local file system. Also, please refrain from top-posting. It makes the posts get very confusing. :( Todd Boyd Web Programmer Todd, if you look at her initial code posted in the other thread, you will see that she WAS infact trying to write the file to a remote server. The two URLs were www.mysite.com/hello.txt and www.yoursite.com/hello.txt That would have been trying to write the new file of http. so he was right in saying what he said. Not sure where you got the above code snippet, but it is not from what she originally posted to the list. -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] fwrite() Append Files
Hi, Right now I enforced the file to read in through HTTP-Request and output it to a local file. Looks like this functioned perfectly after I used append functions after I attempted to write to the file! Thanks to everyone who contributed to this. Alice == Alice Wei MIS 2009 School of Library and Information Science Indiana University Bloomington [EMAIL PROTECTED] From: Jim Lucas [EMAIL PROTECTED] Sent: Friday, June 27, 2008 12:45 PM To: Wei, Alice J. Cc: Per Jessen; php-general@lists.php.net Subject: Re: [PHP] fwrite() Append Files Jim Lucas wrote: Wei, Alice J. wrote: Hi, This is my current code: $lines = file(http://www.mysite.com/hello.txt;); $file=http://www.mysite.com/hello.txt;; You are referring to the file from the website point of view. You must access it from the filesystem point of view $file = '/path/to/public_html/hello.txt'; $ourFileName = hello.txt; $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); fclose($ourFileHandle); $newFileName=http://www.yoursite.com/hello.txt;; Same thing here. You are never going to be able to write to that file. The webserver will never allow it. I guess I should have suggested a work around in this case. You will need to create the file locally and then transfer via ftp/scp/etc... the newly created file to the remote server. I built an FTP client once with PHP using the built in FTP functions. You will probably need to do something similar. echo $newFileName; $result=rename($ourFileName, $newFileName); $ourFileHandle = fopen($ourFileName, 'wb') or die(can't open file); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num = $line) { echo pLine #b{$line_num}/b : . htmlspecialchars($line) . /p; $ourFileHandle = fopen($newFileName, 'wb') or die(can't open file); $content=fwrite($ourFileHandle, htmlspecialchars($line)); echo pThe line: $content has been written into $newFilename/p; } fclose($ourFileHandle); Do you mean to edit $ourFileHandle to fopen($ourFileName, 'wba')? What I really wanted to do is to copy the file directory from $file to $newFileName directory using the cp command or something, but if I cannot do that, writing in and out of the file may be good enough. Alice == Alice Wei MIS 2009 School of Library and Information Science Indiana University Bloomington [EMAIL PROTECTED] From: Per Jessen [EMAIL PROTECTED] Sent: Friday, June 27, 2008 8:26 AM To: php-general@lists.php.net Subject: Re: [PHP] fwrite() Append Files Wei, Alice J. wrote: Hi, I wonder if anyone on the list could tell me how to append the files as I am writing in them. I have a file that has no more than five characters per line, and I would like to keep its spacing between the lines. Right now I have the set up so that it could write in the first line, but the problem is that all the lines after it never get written in to the desired file. You need to open the file in append mode = 'a+'. /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Jim Lucas Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them. Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() Append Files
Wei, Alice J. wrote: Hi, Right now I enforced the file to read in through HTTP-Request and output it to a local file. Looks like this functioned perfectly after I used append functions after I attempted to write to the file! Thanks to everyone who contributed to this. Alice Are you making sure to credit the work and suggestions in your code as required by your class documentation standards? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] fwrite() Append Files
From: Wolf [EMAIL PROTECTED] Sent: Friday, June 27, 2008 2:18 PM To: Wei, Alice J. Cc: php-general@lists.php.net Subject: Re: [PHP] fwrite() Append Files Wei, Alice J. wrote: Hi, Right now I enforced the file to read in through HTTP-Request and output it to a local file. Looks like this functioned perfectly after I used append functions after I attempted to write to the file! Thanks to everyone who contributed to this. Alice Are you making sure to credit the work and suggestions in your code as required by your class documentation standards? I am working for my client who wants to get some tasks done. Had this been for an assignment for a class, I would probably have to contact my instructor about it. Thanks for pointing it out. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite/fclose troubles
Hi all, I've been lurking and reading now for some time, but have decided to come out of the shadows cause I've got an issue that's gonna drive me crazy! I'm developing an application and within this application is a class that is very simple and only serves a singular purpose - to make log entries to help with debugging. Problem is, now I'm debugging the damned logging class that is supposed to be helping me debug the application as I'm putting it together! sigh I've looked and looked all over the place, but I don't seem to be able to find an answer to this problem. The only information that I have found so far deals with permissions and I don't think that's the problem. At first I was getting an access denied error but since setting dir perms and log file perms so that both apache and my user can right to both the directory and the file that one has gone away. Log Directory permissions: /mystuff/logs rwx-rwx-rwx (777) Log file permissions: /mystuff/logs/run.log rwx-rwx-rwx (777) At any rate, the following is the information I'm getting in the apache error_log while working on this particular portion of the application: PHP Warning: fwrite(): supplied argument is not a valid stream resource in /mystuff/inc/Log.inc on line 22, PHP Warning: fclose(): supplied argument is not a valid stream resource in /mystuff/inc/Log.inc on line 23, The Log class: - class Log{ public $path, $entry, $logfile; public function Log(){} public function setLog($path,$file){ $this-path = $path; $this-logfile = $file; } public function writeLog($entry){ // open the file, in this case the log file $h = $this-path/$this-logfile; fopen($h, 'a+'); fwrite($h,$entry); fclose($h); } } Code snippet where attempting to write log entry from program: $pl_log = new Log; $pl_log-setLog($logpath,run.log); $usernanme = $_POST['username']; $password = $_POST['secret']; /** * (debugging) logging incoming values from form: */ $pl_log-writeLog(getDateTime(): Incoming values from Login Form: blah...blah...blah\n); Any help with this would be most appreciated. (be gentle... I'm a PERL program learning PHP OOP) -- Mark If you have found a very wise man, then you've found a man that at one time was an idiot and lived long enough to learn from his own stupidity. == Powered by CentOS5 (RHEL5) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite/fclose troubles
On 19 Mar 2008, at 23:38, Mark Weaver wrote: I've been lurking and reading now for some time, but have decided to come out of the shadows cause I've got an issue that's gonna drive me crazy! I'm developing an application and within this application is a class that is very simple and only serves a singular purpose - to make log entries to help with debugging. Problem is, now I'm debugging the damned logging class that is supposed to be helping me debug the application as I'm putting it together! sigh I've looked and looked all over the place, but I don't seem to be able to find an answer to this problem. The only information that I have found so far deals with permissions and I don't think that's the problem. At first I was getting an access denied error but since setting dir perms and log file perms so that both apache and my user can right to both the directory and the file that one has gone away. Log Directory permissions: /mystuff/logs rwx-rwx- rwx (777) Log file permissions: /mystuff/logs/run.log rwx-rwx-rwx (777) At any rate, the following is the information I'm getting in the apache error_log while working on this particular portion of the application: PHP Warning: fwrite(): supplied argument is not a valid stream resource in /mystuff/inc/Log.inc on line 22, PHP Warning: fclose(): supplied argument is not a valid stream resource in /mystuff/inc/Log.inc on line 23, The Log class: - class Log{ public $path, $entry, $logfile; public function Log(){} public function setLog($path,$file){ $this-path = $path; $this-logfile = $file; } public function writeLog($entry){ // open the file, in this case the log file $h = $this-path/$this-logfile; fopen($h, 'a+'); fwrite($h,$entry); fclose($h); } } RTFM. The fopen function (http://php.net/fopen) will return a stream resource. The fwrite (http://php.net/fwrite) and fclose (http://php.net/fclose - noticing a pattern here?) take that resource as the first parameter. You're passing the filename to those functions, which as the error messages clearly state is not a valid stream resource. Please RTFM carefully before asking here, it'll help save both our sanity and yours! -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite/fclose troubles
Please keep replies on-list so everyone can benefit from the discussion. On 20 Mar 2008, at 00:13, Mark Weaver wrote: Stut wrote: RTFM. The fopen function (http://php.net/fopen) will return a stream resource. The fwrite (http://php.net/fwrite) and fclose (http://php.net/fclose - noticing a pattern here?) take that resource as the first parameter. You're passing the filename to those functions, which as the error messages clearly state is not a valid stream resource. Please RTFM carefully before asking here, it'll help save both our sanity and yours! WEll thank stut for the sage advise. However, I had Read The Fuckin Manual and clearly had missed the part you so curtly put forth which is why I asked about it. Geez! I think I'll go back to lurking for pete's sake. Having a bad day? I've had a great day, thanks for asking. Bit depressed to find out that Arthur C. Clarke died last night but apart from that it's been extremely productive. Now, thank stut - is that like thank god? If so please don't do that, I'm pretty sure I'd be a huge disappointment as a deity. Maybe it's just me but the signature of a function you're using is a pretty fundamental part of the manual to have missed. I kinda meant it when I said carefully. It's also a bit strange to have missed it the second and third times you read the relevant parts of the manual in your attempt to work out what was causing the error message. You did that too right? Incidentally, I hope you remove or disable that code before going into production. Multiple processes/threads trying to append to the same file is never a good idea. I help people in my own sarcastic way. If you've been lurking on the list for a while you might have noticed that. If not then it's possible I've mellowed a bit as the years have passed, but I doubt it. If you don't like it you are free to ignore me - I try not to force my advice on anyone, that would be offensive. Now you have a great day, mine's over! But never fear, a whole new day with brand new possibilities for sarcasm and snide remarks starts in a few short hours. For now, that's all folks! -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fwrite Function
On Sat, February 16, 2008 6:03 am, Yuval Schwartz wrote: Hello, Can you please help me, I am writing code where I create a file and write to it from a form on a webpage and then read and display this file on the webpage. I want to change the color of the text that is written to the file. Do you know how I can do this? This is some of my code if you need clarification: * $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,'a') or die(can't open file); fwrite($boardFileHandle, $name); fwrite($boardFileHandle, $talk); fclose($boardFileHandle); } $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,r); $talkR = fread($boardFileHandle, filesize($boardFile)); fclose($boardFileHandle); echo $talkR;* I would recommend not trying to colorize the text in the file, but rather to colorize it upon display... echo div style=\color: red;\$talkR;/div\n; -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Fwrite Function
Hello, Can you please help me, I am writing code where I create a file and write to it from a form on a webpage and then read and display this file on the webpage. I want to change the color of the text that is written to the file. Do you know how I can do this? This is some of my code if you need clarification: * $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,'a') or die(can't open file); fwrite($boardFileHandle, $name); fwrite($boardFileHandle, $talk); fclose($boardFileHandle); } $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,r); $talkR = fread($boardFileHandle, filesize($boardFile)); fclose($boardFileHandle); echo $talkR;* ** ** Thanks
RE: [PHP] Fwrite Function
Its a text file and so doesn't support markup. You could write out html into the file that does mark it up and could be displayed to the user via the browser...or you could use regex or str_replace to mark up certain text on the read of the file to display to the user bastien Date: Sat, 16 Feb 2008 14:03:26 +0200 From: [EMAIL PROTECTED] To: php-general@lists.php.net Subject: [PHP] Fwrite Function Hello, Can you please help me, I am writing code where I create a file and write to it from a form on a webpage and then read and display this file on the webpage. I want to change the color of the text that is written to the file. Do you know how I can do this? This is some of my code if you need clarification: * $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,'a') or die(can't open file); fwrite($boardFileHandle, $name); fwrite($boardFileHandle, $talk); fclose($boardFileHandle); } $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,r); $talkR = fread($boardFileHandle, filesize($boardFile)); fclose($boardFileHandle); echo $talkR;* ** ** Thanks _ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fwrite Function
Yuval Schwartz wrote: Hello, Can you please help me, I am writing code where I create a file and write to it from a form on a webpage and then read and display this file on the webpage. I want to change the color of the text that is written to the file. Do you know how I can do this? This is some of my code if you need clarification: * $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,'a') or die(can't open file); fwrite($boardFileHandle, $name); fwrite($boardFileHandle, $talk); fclose($boardFileHandle); } $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,r); $talkR = fread($boardFileHandle, filesize($boardFile)); fclose($boardFileHandle); echo $talkR;* ** ** Thanks First question is -- why aren't you using a database for this information? I would recommend sqlite (http://www.sqlite.org/) Now that that's taken care of, if you're trying to color the text on output, I would do it like this: ___ ?php $name = nick; //added for testing $talk = a message; //added for testing $NAMEFORMAT = 'font color=red'; $MESSAGEFORMAT = 'font color=blue'; $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,'a') or die(can't open file); /* * Here we are going to write to the file, notice I added another line that prints a comma. This will be useful so that you can easily parse out and potentially format the 2 elements at will */ fwrite($boardFileHandle, $name); fwrite($boardFileHandle, ,); // added fwrite($boardFileHandle, $talk); fclose($boardFileHandle); $boardFile = MessageBoard.txt; $boardFileHandle = fopen($boardFile,r); /* removed $talkR = fread($boardFileHandle, filesize($boardFile)); */ while (($data = fgetcsv($boardFileHandle, 1000, ,)) !== FALSE) { /* * put 1000byte buffer to $data, this also goes 1 line at a time. */ echo $NAMEFORMAT . $data[0] . /font; // print the name echo $MESSAGEFORMAT . $data[1]; // print the text } fclose($boardFileHandle); ? If you have any questions regarding the implementation I suggest the following reading material: http://us3.php.net/manual/en/function.fgetcsv.php Good luck! == Nick Stinemates ([EMAIL PROTECTED]) http://nick.stinemates.org AIM: Nick Stinemates MSN: [EMAIL PROTECTED] Yahoo: [EMAIL PROTECTED] == -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite() timeout
Hi, I am using the fsockopen(), fwrite() and fread() functions to get a web page from a remote server. The remote server is currently down and I see the code hangs on the fwrite() call. Is there a way how to set a timeout for the fwrite() remote call? I have found the stream_set_timeout(), but it seems not to be effective on the fwrite(), only on fread(). Thanks, Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite() timeout
Hi, I am using the fsockopen(), fwrite() and fread() functions to get a web page from a remote server. The remote server is currently down and I see the code hangs on the fwrite() call. Is there a way how to set a timeout for the fwrite() remote call? I have found the stream_set_timeout(), but it seems not to be effective on the fwrite(), only on fread(). Thanks, Martin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite fopen problem
System Windows XP: PHP 5 I have a folder in which I want to write files. The IUSR_... user has full control, yet I am still getting failed to open stream and permission dined errors. Any suggestions? I have done this same task on many XP machines and 2003 servers. I am totally stumped. Jeremy Schreckhise, M.B.A.
RE: [PHP] fwrite fopen problem
Fixed by re-assigning IUSR... to directory security. Cheers. -Original Message- From: Jeremy Schreckhise [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 16, 2006 10:59 AM To: php-general@lists.php.net Subject: [PHP] fwrite fopen problem System Windows XP: PHP 5 I have a folder in which I want to write files. The IUSR_... user has full control, yet I am still getting failed to open stream and permission dined errors. Any suggestions? I have done this same task on many XP machines and 2003 servers. I am totally stumped. Jeremy Schreckhise, M.B.A. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite/fopen
fwrite failed for quota disc exceeded, so I end up with empty file. the algorithm is something like : if (! $fp = @fopen($config['pagecachedir'].$path.$tmp_value,'wb')) { $errorLog .= Writing problem for .$config['pagecachedir']. $path$tmp_value!\n; } else { $txt_length = strlen($txt); if (@fwrite($fp,$txt,$txt_length) != $txt_length) { $errorLog .= Writing problem in file !\n; @fclose($fp); @unlink($config['pagecachedir'].$path.$tmp_value); } else { //everything is OK @fclose($fp); } On 6/11/05, Richard Lynch [EMAIL PROTECTED] wrote: You would probably have to fclose it before you can unlink it, and if it's fargled enough that fwrite failed, you probably can't fclose it successfully... Your best bet would be to put the filename into a database table, then run a cron job that deletes all the files in that table, and only takes them out of the table if they are successfully deleted. Course, you then want to be sure you have UNIQUE filenames so you don't delete a good file later. On Fri, June 10, 2005 4:03 pm, Mister Jack said: Hi, I having a problem at the moment, I open a file, try to write in it, and then remove the file if the write goes wrong (if write count != of my initial buffer length). But I still get some empty file (and then a blank page). Could possibly fopen (with a 'wb' flag, and under freebsd 4.11) failed but still create that empty file ? Where could I get more info on the behavior of fopen/fwrite ? Thanks for your help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite/fopen
Hi, I having a problem at the moment, I open a file, try to write in it, and then remove the file if the write goes wrong (if write count != of my initial buffer length). But I still get some empty file (and then a blank page). Could possibly fopen (with a 'wb' flag, and under freebsd 4.11) failed but still create that empty file ? Where could I get more info on the behavior of fopen/fwrite ? Thanks for your help. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite and sort
i have a form with checkboxes which after POST it writes to a file. i would like to allow the user to sort the selected checkbox filename in the order they want it written to file. so i was thinking creating an input text box where they can enter a number, then have it written to file in that order.. question is how? the script starts like such: foreach($_POST['map'] AS $file) { if(file_exists('/maps/'.trim($file))) { $found .= $file; } } if (file_exists($mapcycle) $found) { $fp = fopen($mapcycle, 'w'); fwrite($fp, $found); fclose($fp); } any help is appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite and sort
http://php.net/asort On Mon, March 21, 2005 12:29 pm, Sebastian said: i have a form with checkboxes which after POST it writes to a file. i would like to allow the user to sort the selected checkbox filename in the order they want it written to file. so i was thinking creating an input text box where they can enter a number, then have it written to file in that order.. question is how? the script starts like such: foreach($_POST['map'] AS $file) { if(file_exists('/maps/'.trim($file))) { $found .= $file; } } if (file_exists($mapcycle) $found) { $fp = fopen($mapcycle, 'w'); fwrite($fp, $found); fclose($fp); } any help is appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() seems to destroy Special Characters
Dennis Lahay wrote: I'm having trouble with writing special charcaters to a text file. The characters are your run-of-the-mill accented characters. Passing them back and forth in the database and displaying them on screen is NOT a problem. code snippet: $row = mysql_fetch_array($query_result, MYSQL_ASSOC); foreach ($exportOrder as $key = $value) { // makes tab-delimited file from array if (array_key_exists($key, $row)) { $bigString .= $row[$key] . \t; } else { $bigString .= \t; } } print $bigString; $filename = ../../../Volumes/FILEJOB/DB Art IN/ . $row['currentSVVersion']; if (!$file = fopen($filename, 'w+')) { print Cannot open file ($filename); exit; } fwrite($file, $bigString); fclose($file); I print the string immediately before I write the file. It looks like this (i hope this formats correctly for the list): INGRDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, PICES I write the file, open it up in BBEdit (or your favorite text editor) and it looks like this: INGRDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, PICES ? Why would I lose those special characters when writing to a text file? How can I avoid this? The text file will be opened offline, so using Eacute; and other character entities won't work. I've tried: - $file = fopen($filename, 'w+b'); adding binary flag doesn't affect anything - Iooking at php.ini; nothing stood out Any suggestions? [Mac OSX 10.3.6 : PHP 4.3.2 : MySQL 4.0.18 : Apache 1.3.29] You are not loosing them, only bbedit does not display them in the original charset. Look in the bbedit menu or configuration if you can find some character encoding setting -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() seems to destroy Special Characters
The file doesn't exist, so I need to create it first. So I did this: $filename = ../../../Volumes/FILEJOB/ . $row['currentSVVersion']; if (!$file = fopen($filename, 'w+')) { print Cannot open file ($filename); exit; } fclose($file); Then I wrote to it using your suggestion: if (!$file = fopen($filename, 'wb')) { print Cannot open file ($filename); exit; } fwrite($file, $bigString); fclose($file); Still didn't work. Anyone else have any suggestions? On Nov 17, 2004, at 5:30 PM, Tom Z. Meinlschmidt wrote: hi, try to fopen() the file for writing only by fopen('filename','wb').. the same for reading - fopen('filename','rb') ... /tom On Wed, Nov 17, 2004 at 04:26:20PM -0600 Dennis Lahay [EMAIL PROTECTED] wrote: I'm having trouble with writing special charcaters to a text file. The characters are your run-of-the-mill accented characters. Passing them back and forth in the database and displaying them on screen is NOT a problem. code snippet: $row = mysql_fetch_array($query_result, MYSQL_ASSOC); foreach ($exportOrder as $key = $value) { // makes tab-delimited file from array if (array_key_exists($key, $row)) { $bigString .= $row[$key] . \t; } else { $bigString .= \t; } } print $bigString; $filename = ../../../Volumes/FILEJOB/DB Art IN/ . $row['currentSVVersion']; if (!$file = fopen($filename, 'w+')) { print Cannot open file ($filename); exit; } fwrite($file, $bigString); fclose($file); I print the string immediately before I write the file. It looks like this (i hope this formats correctly for the list): INGRÉDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, ÉPICES ? Â ? Ç ? É ? Ë Î ? Ô ? Ü ? I write the file, open it up in BBEdit (or your favorite text editor) and it looks like this: INGR?DIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, ?PICES ? ? ? ? ? ? ? ?? ? ? ? ? ? Why would I lose those special characters when writing to a text file? How can I avoid this? The text file will be opened offline, so using Eacute; and other character entities won't work. I've tried: - $file = fopen($filename, 'w+b'); adding binary flag doesn't affect anything - Iooking at php.ini; nothing stood out Any suggestions? [Mac OSX 10.3.6 : PHP 4.3.2 : MySQL 4.0.18 : Apache 1.3.29] D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() seems to destroy Special Characters
Ah, if were only that simple but, alas, it is not. I have opened other documents that contain these special characters and BBEdit has displayed them properly. On Nov 18, 2004, at 8:23 AM, Marek Kilimajer wrote: You are not loosing them, only bbedit does not display them in the original charset. Look in the bbedit menu or configuration if you can find some character encoding setting Dennis Lahay wrote: I'm having trouble with writing special charcaters to a text file. The characters are your run-of-the-mill accented characters. Passing them back and forth in the database and displaying them on screen is NOT a problem. code snippet: $row = mysql_fetch_array($query_result, MYSQL_ASSOC); foreach ($exportOrder as $key = $value) { // makes tab-delimited file from array if (array_key_exists($key, $row)) { $bigString .= $row[$key] . \t; } else { $bigString .= \t; } } print $bigString; $filename = ../../../Volumes/FILEJOB/DB Art IN/ . $row['currentSVVersion']; if (!$file = fopen($filename, 'w+')) { print Cannot open file ($filename); exit; } fwrite($file, $bigString); fclose($file); I print the string immediately before I write the file. It looks like this (i hope this formats correctly for the list): INGRDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, PICES I write the file, open it up in BBEdit (or your favorite text editor) and it looks like this: INGRDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, PICES ? Why would I lose those special characters when writing to a text file? How can I avoid this? The text file will be opened offline, so using Eacute; and other character entities won't work. I've tried: - $file = fopen($filename, 'w+b'); adding binary flag doesn't affect anything - Iooking at php.ini; nothing stood out Any suggestions? [Mac OSX 10.3.6 : PHP 4.3.2 : MySQL 4.0.18 : Apache 1.3.29] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() seems to destroy Special Characters
Dennis Lahay wrote: Ah, if were only that simple but, alas, it is not. I have opened other documents that contain these special characters and BBEdit has displayed them properly. Are you using the same charset for both? What is the original source of the data? html form? then they are in the charset of the html page On Nov 18, 2004, at 8:23 AM, Marek Kilimajer wrote: You are not loosing them, only bbedit does not display them in the original charset. Look in the bbedit menu or configuration if you can find some character encoding setting Dennis Lahay wrote: I'm having trouble with writing special charcaters to a text file. The characters are your run-of-the-mill accented characters. Passing them back and forth in the database and displaying them on screen is NOT a problem. code snippet: $row = mysql_fetch_array($query_result, MYSQL_ASSOC); foreach ($exportOrder as $key = $value) { // makes tab-delimited file from array if (array_key_exists($key, $row)) { $bigString .= $row[$key] . \t; } else { $bigString .= \t; } } print $bigString; $filename = ../../../Volumes/FILEJOB/DB Art IN/ . $row['currentSVVersion']; if (!$file = fopen($filename, 'w+')) { print Cannot open file ($filename); exit; } fwrite($file, $bigString); fclose($file); I print the string immediately before I write the file. It looks like this (i hope this formats correctly for the list): INGRDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, PICES I write the file, open it up in BBEdit (or your favorite text editor) and it looks like this: INGRDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, PICES ? Why would I lose those special characters when writing to a text file? How can I avoid this? The text file will be opened offline, so using Eacute; and other character entities won't work. I've tried: - $file = fopen($filename, 'w+b'); adding binary flag doesn't affect anything - Iooking at php.ini; nothing stood out Any suggestions? [Mac OSX 10.3.6 : PHP 4.3.2 : MySQL 4.0.18 : Apache 1.3.29] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() seems to destroy Special Characters
On Thursday 18 November 2004 23:46, Dennis Lahay wrote: Ah, if were only that simple but, alas, it is not. I have opened other documents that contain these special characters and BBEdit has displayed them properly. After creating the file, use PHP to read it back and display its contents. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* #ifdef STUPIDLY_TRUST_BROKEN_PCMD_ENA_BIT linux-2.4.0-test2/drivers/ide/cmd640.c */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite() seems to destroy Special Characters
I'm having trouble with writing special charcaters to a text file. The characters are your run-of-the-mill accented characters. Passing them back and forth in the database and displaying them on screen is NOT a problem. code snippet: $row = mysql_fetch_array($query_result, MYSQL_ASSOC); foreach ($exportOrder as $key = $value) { // makes tab-delimited file from array if (array_key_exists($key, $row)) { $bigString .= $row[$key] . \t; } else { $bigString .= \t; } } print $bigString; $filename = ../../../Volumes/FILEJOB/DB Art IN/ . $row['currentSVVersion']; if (!$file = fopen($filename, 'w+')) { print Cannot open file ($filename); exit; } fwrite($file, $bigString); fclose($file); I print the string immediately before I write the file. It looks like this (i hope this formats correctly for the list): INGRDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, PICES I write the file, open it up in BBEdit (or your favorite text editor) and it looks like this: INGRDIENTS : VINAIGRE, EAU, GRAINES DE MOUTARDE, SEL, CURCUMA, PICES ? Why would I lose those special characters when writing to a text file? How can I avoid this? The text file will be opened offline, so using Eacute; and other character entities won't work. I've tried: - $file = fopen($filename, 'w+b'); adding binary flag doesn't affect anything - Iooking at php.ini; nothing stood out Any suggestions? [Mac OSX 10.3.6 : PHP 4.3.2 : MySQL 4.0.18 : Apache 1.3.29] D -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] fwrite, fopen, or fread limit?
I highly doubt that was all. Now uploads bigger than 7megs are allowed, you should also make sure your script is able to deal with it files LARGER than that. Hmm, maybe this didn't seem to make much sense. What I'm talking about is this: memory_limit = 8M ; Maximum amount of memory a script may consume (8MB) When using fwrite you probably load the entire file into memory and have a high chance on exceeding the size of 8MB. Or if you're smart you do it line by line and there's less problem with it. Also I'd like to point you to the move_uploaded_file function. Just in case you didn't know about it. Greetz, Wouter ( sorry for the messy kinda post. I'm just all too confused about the disappointing Matrix Revolutions... I'd like to compare it to a third-level rip off of The Lord of the Rings (trilogy) meets Star Wars ) -Original Message- From: Mike At Spy [mailto:[EMAIL PROTECTED] Sent: Tuesday 04 November 2003 18:55 To: Roger Spears Cc: [EMAIL PROTECTED] Subject: RE: [PHP] fwrite, fopen, or fread limit? Yes, that was it. Thanks! :) -Mike -Original Message- From: Roger Spears [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 04, 2003 12:45 PM To: Mike At Spy Subject: Re: [PHP] fwrite, fopen, or fread limit? check the php.ini file, there may be a file upload limit placed there. I ran into a similar problem awhile backI think it's called max_file_upload or something like that... Thanks, Roger Mike At Spy wrote: Does anyone know if the commands for fwrite, fopen, or fread have memory limits in dealing with large files? I created a system for uploading files to a server. Small files work fine. Larger ones (around 7 megs) do not work at all. Thanks, -Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite, fopen, or fread limit?
Does anyone know if the commands for fwrite, fopen, or fread have memory limits in dealing with large files? I created a system for uploading files to a server. Small files work fine. Larger ones (around 7 megs) do not work at all. Thanks, -Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] fwrite, fopen, or fread limit?
[snip] Does anyone know if the commands for fwrite, fopen, or fread have memory limits in dealing with large files? I created a system for uploading files to a server. Small files work fine. Larger ones (around 7 megs) do not work at all. [/snip] Have you checked your upload_max_filesize in php.ini? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] fwrite, fopen, or fread limit?
Yes, that was it. Thanks! :) -Mike -Original Message- From: Roger Spears [mailto:[EMAIL PROTECTED] Sent: Tuesday, November 04, 2003 12:45 PM To: Mike At Spy Subject: Re: [PHP] fwrite, fopen, or fread limit? check the php.ini file, there may be a file upload limit placed there. I ran into a similar problem awhile backI think it's called max_file_upload or something like that... Thanks, Roger Mike At Spy wrote: Does anyone know if the commands for fwrite, fopen, or fread have memory limits in dealing with large files? I created a system for uploading files to a server. Small files work fine. Larger ones (around 7 megs) do not work at all. Thanks, -Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite int or float
Is there some easy way to fwrite a 32 bit int or float? -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite int or float
ok I see to use the pack command, but now how do I format to 32 bit little endian? Ted Huntington wrote: Is there some easy way to fwrite a 32 bit int or float? -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite int or float
I should have type signed 32 bit little endian and little endian float. Ted Huntington wrote: ok I see to use the pack command, but now how do I format to 32 bit little endian? Ted Huntington wrote: Is there some easy way to fwrite a 32 bit int or float? -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite int or float
I basically solved this problem of writing a 32 bit float in little endian on a big endian computer using: $num2=pack(f,$num); fwrite($fp,$num2[3],1); fwrite($fp,$num2[2],1); fwrite($fp,$num2[1],1); fwrite($fp,$num2[0],1); for floating point (I am working on a UNIX [big endian] making a file for i86 [little endian]). The more info, the better, perhaps some body else will search and find this if ever the need. Ted Huntington wrote: I should have type signed 32 bit little endian and little endian float. Ted Huntington wrote: ok I see to use the pack command, but now how do I format to 32 bit little endian? Ted Huntington wrote: Is there some easy way to fwrite a 32 bit int or float? -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Ted Huntington Programmer Analyst I Main Library University of California, Irvine PO Box 19557 Irvine, CA 92623-9557 Phone Bus Off 949 824 8926 Phone MRC 949 824 1674 emesg: [EMAIL PROTECTED] webpage: http://business.lib.uci.edu/webpages/ted.htm Stop violence, teach science. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite int or float
* Thus wrote Ted Huntington ([EMAIL PROTECTED]): I basically solved this problem of writing a 32 bit float in little endian on a big endian computer using: $num2=pack(f,$num); fwrite($fp,$num2[3],1); fwrite($fp,$num2[2],1); fwrite($fp,$num2[1],1); fwrite($fp,$num2[0],1); for floating point (I am working on a UNIX [big endian] making a file for i86 [little endian]). The more info, the better, perhaps some body else will search and find this if ever the need. There was a large discussion on this about two weeks ago, check the archives on 'big endian' Curt -- I used to think I was indecisive, but now I'm not so sure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite not working in php3
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: hi there i have a little problem writing files on a php3 server this code worked yesterday but isnt $handle = fopen(/www_tools/apache/htdocs/phptest/temp_real/test.inc,'a'); Test your $handle to see if you successfully opened the file. if (! $handle) { // check permissions die('croak: can't open the file'); } $buffer = test; echo fwrite($handle,$buffer,4000); fclose($handle); i get a filesize of 0 and nothing writes to it what could it be ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite not working in php3
sorry guys the server was full again , doesnt return any error at all funny hey On Thursday 17 July 2003 09:46, [EMAIL PROTECTED] wrote: hi there i have a little problem writing files on a php3 server this code worked yesterday but isnt $handle = fopen(/www_tools/apache/htdocs/phptest/temp_real/test.inc,'a'); $buffer = test; echo fwrite($handle,$buffer,4000); fclose($handle); i get a filesize of 0 and nothing writes to it what could it be ? What does the error logs say? And try following the examples in the manual which incorporates the error checking that your code lacks. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The wages of sin are unreported. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite not working in php3
hi there i have a little problem writing files on a php3 server this code worked yesterday but isnt $handle = fopen(/www_tools/apache/htdocs/phptest/temp_real/test.inc,'a'); $buffer = test; echo fwrite($handle,$buffer,4000); fclose($handle); i get a filesize of 0 and nothing writes to it what could it be ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite not working in php3
On Thursday 17 July 2003 09:46, [EMAIL PROTECTED] wrote: hi there i have a little problem writing files on a php3 server this code worked yesterday but isnt $handle = fopen(/www_tools/apache/htdocs/phptest/temp_real/test.inc,'a'); $buffer = test; echo fwrite($handle,$buffer,4000); fclose($handle); i get a filesize of 0 and nothing writes to it what could it be ? What does the error logs say? And try following the examples in the manual which incorporates the error checking that your code lacks. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* The wages of sin are unreported. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite() question
Hello, I have a block of code: ?php if ($_POST['news']) { $fp = fopen( news.txt, w); $success = fwrite( $fp, $POST_['news'] ); fclose($fp); if (!success) { echo punable to write to news.txt/p; exit; } Header(Location: http://archives1.mdah.state.ms.us/news.php; ); } ? and when I access it, I get the error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /usr/local/apache2/htdocs/updatenews.php on line 5 and line 5 is: $success = fwrite( $fp, $POST_['news'] ); which looks ok to me. When I take out the around $POST_['news'] it doesn't generate an error, but then it doesn't write anything to news.txt. news.txt is owned by nobody with 755 and apache runs as nobody. I'd appreciate any help. Thanks! Adam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() question
you should use $_POST['news'] instead of $POST_['news']. ans you also should'nt put around variables ;) Hello, I have a block of code: ?php if ($_POST['news']) { $fp = fopen( news.txt, w); $success = fwrite( $fp, $POST_['news'] ); fclose($fp); if (!success) { echo punable to write to news.txt/p; exit; } Header(Location: http://archives1.mdah.state.ms.us/news.php; ); } ? and when I access it, I get the error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /usr/local/apache2/htdocs/updatenews.php on line 5 and line 5 is: $success = fwrite( $fp, $POST_['news'] ); which looks ok to me. When I take out the around $POST_['news'] it doesn't generate an error, but then it doesn't write anything to news.txt. news.txt is owned by nobody with 755 and apache runs as nobody. I'd appreciate any help. Thanks! Adam -- Adrian mailto:[EMAIL PROTECTED] www: http://www.planetcoding.net www: http://www.webskyline.de -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() question
Hi, when I do that, nothing is written to news.txt, and I'm not sure why. This is the entire script: ?php if ($_POST['news']) { $fp = fopen( news.txt, w); $success = fwrite( $fp, $POST_['news'] ); fclose($fp); if (!success) { echo punable to write to news.txt/p; exit; } Header(Location: http://archives1.mdah.state.ms.us/news.php; ); } ? html headtitleNews update/title/head body bgcolor=white pPlease make your changes below and then click submit:/p ?php if ( $_GET['action'] = update) { echo form action=$PHP_SELF METHOD=POST; echo textarea name=news rows=10 cols=50 wrap=virtual; $fp = fopen( news.txt, 'r' ); while ( ! feof ($fp) ) { $line = fgets( $fp, ); $line = htmlspecialchars(nl2br($line)); echo $line; } echo /textarea br input type=submit value=submit name=submit /form; fclose($fp); } ? a href=http://archives1.mdah.state.ms.us/news.php;home/a /body/html Adam On Tue, 1 Jul 2003, Adrian wrote: you should use $_POST['news'] instead of $POST_['news']. ans you also should'nt put around variables ;) Hello, I have a block of code: ?php if ($_POST['news']) { $fp = fopen( news.txt, w); $success = fwrite( $fp, $POST_['news'] ); fclose($fp); if (!success) { echo punable to write to news.txt/p; exit; } Header(Location: http://archives1.mdah.state.ms.us/news.php; ); } ? and when I access it, I get the error: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /usr/local/apache2/htdocs/updatenews.php on line 5 and line 5 is: $success = fwrite( $fp, $POST_['news'] ); which looks ok to me. When I take out the around $POST_['news'] it doesn't generate an error, but then it doesn't write anything to news.txt. news.txt is owned by nobody with 755 and apache runs as nobody. I'd appreciate any help. Thanks! Adam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() question
On Tuesday 01 July 2003 22:12, Adam Williams wrote: when I do that, nothing is written to news.txt, and I'm not sure why. Well find out why! This is the entire script: ?php if ($_POST['news']) { $fp = fopen( news.txt, w); Add some error-checking to see whether fopen() was successful. See examples in manual for details. $success = fwrite( $fp, $POST_['news'] ); As has already been pointed out you don't need the double-quotes. And it should be $_POST['news']. fclose($fp); if (!success) This should be: if (!$success) And please trim your post! -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- /* We come to bury DOS, not to praise it. (Paul Vojta, [EMAIL PROTECTED], paraphrasing a quote of Shakespeare) */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite() debugging
Could somebody please tell me what I'm doing wrong here? The code is: ?php $filename= tables/contacts.txt; $fd=fopen($filename, a); fwrite($filename, xyz); fclose($fd); ? And I get the following error message: Warning: fwrite(): supplied argument is not a valid File-Handle resource in c:\archivos de programa\apache group\apache\htdocs\visitrep\report_options.inc on line 111 Thanks a lot in advance and happy new year! Alberto Brea http://estudiobrea.com
Re: [PHP] fwrite() debugging
The $fd is the file handler now not the $filename. Timothy Hitchens (HiTCHO) [EMAIL PROTECTED] HiTCHO | Open Platform Web Development Consutling - Outsourcing - Training - Support - Original Message - From: Alberto Brea [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, January 01, 2003 6:27 AM Subject: [PHP] fwrite() debugging Could somebody please tell me what I'm doing wrong here? The code is: ?php $filename= tables/contacts.txt; $fd=fopen($filename, a); fwrite($filename, xyz); fclose($fd); ? And I get the following error message: Warning: fwrite(): supplied argument is not a valid File-Handle resource in c:\archivos de programa\apache group\apache\htdocs\visitrep\report_options.inc on line 111 Thanks a lot in advance and happy new year! Alberto Brea http://estudiobrea.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() debugging
Try ?php $filename= tables/contacts.txt; $fd=fopen($filename, a); if(!($fd)){ die(Unable to open file); } fwrite($fd, xyz); fclose($fd); ? *** REPLY SEPARATOR *** On 31/12/2002 at 5:27 PM Alberto Brea wrote: Could somebody please tell me what I'm doing wrong here? The code is: ?php $filename= tables/contacts.txt; $fd=fopen($filename, a); fwrite($filename, xyz); fclose($fd); ? And I get the following error message: Warning: fwrite(): supplied argument is not a valid File-Handle resource in c:\archivos de programa\apache group\apache\htdocs\visitrep\report_options.inc on line 111 Thanks a lot in advance and happy new year! Alberto Brea http://estudiobrea.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() blank-line Quirk?
On Sunday 22 December 2002 13:52, Noel Wade wrote: Hi All, Relatively new PHP coder (was in an MS / ASP shop before)... I'm doing some flat-file manipulation (please, spare me the database comments, I'm working on it!), and I'm having to read strings out of one file and copy them into another until a while() condition is satisfied. The problem is, I seem to always end up with a blank line at the end of my files (which then screws up later file-processing) - I'm assuming because of the \n that fwrite() appends to the end of each string... fwrite() only writes what you tell it to write ... Is there a simple way to get rid of this blank line or somehow get fwrite() to NOT put a newline on the end of a string? ... so it must be your code which is putting it there? Please post your code. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* A rock pile ceases to be a rock pile the moment a single man contemplates it, bearing within him the image of a cathedral. -- Antoine de Saint-Exupery */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite() blank-line Quirk?
Hi All, Relatively new PHP coder (was in an MS / ASP shop before)... I'm doing some flat-file manipulation (please, spare me the database comments, I'm working on it!), and I'm having to read strings out of one file and copy them into another until a while() condition is satisfied. The problem is, I seem to always end up with a blank line at the end of my files (which then screws up later file-processing) - I'm assuming because of the \n that fwrite() appends to the end of each string... Is there a simple way to get rid of this blank line or somehow get fwrite() to NOT put a newline on the end of a string? Thanks in Advance, --Noel Wade -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite and line breaks
I know that fwrite needs to be written as such: $Open=fopen($MyFile, w); fwrite($Open, Text to add to file.\n); The file is being saved on a Unix server, but Windows/Mac users will be downloading the file. How can I create line breaks that notepad/textpad will use to create new lines, instead of boxes where the break should be? I have tried changing w to wb as suggested on php.net, but that does not work either and I am out of ideas. Jami
[PHP] fwrite()ing predefined variables
Hi, Could somebody please tell me why I can't print pre-defined variables to a file with fwrite()? The code I use is this: $filename = '../vlog.txt'; $fd= fopen($filename, 'a'); $a= date(YmdHi); $b= basename($PHP_SELF); $c= $HTTP_USER_AGENT; $d= $HTTP_HOST; $e= $_SERVER['HTTP_HOST']; $f= xxx; $g= yyy; fwrite($fd, $a#$b#$c#$d#$e#$f#$g\n); fclose($fd); And the output I get in the target file is this: 200212101552localhost#xxx#yyy Thanks a lot in advance Alberto
Re: [PHP] fwrite()ing predefined variables
On Wednesday 11 December 2002 03:00, Alberto Brea wrote: Hi, Could somebody please tell me why I can't print pre-defined variables to a file with fwrite()? The code I use is this: $filename = '../vlog.txt'; $fd= fopen($filename, 'a'); $a= date(YmdHi); $b= basename($PHP_SELF); $c= $HTTP_USER_AGENT; $d= $HTTP_HOST; $e= $_SERVER['HTTP_HOST']; $f= xxx; $g= yyy; fwrite($fd, $a#$b#$c#$d#$e#$f#$g\n); fclose($fd); And the output I get in the target file is this: 200212101552localhost#xxx#yyy Because some pre-defined variables aren't pre-defined anymore. Read the variables section of the manual or use phpinfo() to see which really are pre-defined. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Q: How do you know when you're in the ethnic section of Vermont? A: The maple sap buckets are hanging on utility poles. */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite()ing predefined variables
All these variables show on the browser quite well from a regular .php file, so they are still pre-defined, but I can't fprint() them to a text file.
[PHP] fwrite() - problems....
I have a large string that I want to written to a new file. Let's say the string contains the characters, hello! and I want the filename to be hello.txt Here is the code I have... $filename = hello.txt; $outputstring = hello; fwrite($filename, $outputstring); ...and of course it isn't working. I get this error... Warning: Supplied argument is not a valid File-Handle resource in /home/filanya/www/biopsy/export.php What am I doing wrong? ThANKS!!
RE: [PHP] fwrite() - problems....
$fp = fopen($filename, w); fwrite($fp, $outputstring); READ THE DOCS -Original Message- From: Phil Schwarzmann [mailto:[EMAIL PROTECTED]] Sent: Monday, April 08, 2002 12:51 PM To: [EMAIL PROTECTED] Subject: [PHP] fwrite() - problems I have a large string that I want to written to a new file. Let's say the string contains the characters, hello! and I want the filename to be hello.txt Here is the code I have... $filename = hello.txt; $outputstring = hello; fwrite($filename, $outputstring); ...and of course it isn't working. I get this error... Warning: Supplied argument is not a valid File-Handle resource in /home/filanya/www/biopsy/export.php What am I doing wrong? ThANKS!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() - problems....
you are missing fopen() before calling fwrite() - Original Message - From: Phil Schwarzmann [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, April 08, 2002 1:50 PM Subject: [PHP] fwrite() - problems I have a large string that I want to written to a new file. Let's say the string contains the characters, hello! and I want the filename to be hello.txt Here is the code I have... $filename = hello.txt; $outputstring = hello; fwrite($filename, $outputstring); ...and of course it isn't working. I get this error... Warning: Supplied argument is not a valid File-Handle resource in /home/filanya/www/biopsy/export.php What am I doing wrong? ThANKS!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] fwrite() - problems....
On Mon, 8 Apr 2002, Phil Schwarzmann wrote: $filename = hello.txt; $outputstring = hello; fwrite($filename, $outputstring); http://php.net/fwrite miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] fwrite????
Hello all, Is is possible to just append to the end of a file using fwrite??? Currently I am reading the contents for the file into an array then add to the array what I want and rewrite the file from the array... And well that is just silly... How else would I do this?? -- 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] fwrite????
when you open the file with fopen(), use the 'a' (writing only) or 'a+' (reading and writing) arguments ie: int fopen (somefile.txt, a); ... *'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. *'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. ... info from http://www.php.net/manual/en/function.fopen.php - Original Message - From: Brian C. Doyle [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, August 20, 2001 11:06 Subject: [PHP] fwrite Hello all, Is is possible to just append to the end of a file using fwrite??? Currently I am reading the contents for the file into an array then add to the array what I want and rewrite the file from the array... And well that is just silly... How else would I do this?? -- 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 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] fwrite????
Thank you for your time I did not even look at the fopen... DUH Sorry about not researching properly... At 11:14 AM 8/20/01 -0700, Anton Stroganov wrote: when you open the file with fopen(), use the 'a' (writing only) or 'a+' (reading and writing) arguments ie: int fopen (somefile.txt, a); ... *'a' - Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. *'a+' - Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. ... info from http://www.php.net/manual/en/function.fopen.php - Original Message - From: Brian C. Doyle [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, August 20, 2001 11:06 Subject: [PHP] fwrite Hello all, Is is possible to just append to the end of a file using fwrite??? Currently I am reading the contents for the file into an array then add to the array what I want and rewrite the file from the array... And well that is just silly... How else would I do this?? -- 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 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 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] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14
In article 012101c0c69b$b01b8d00$8b1412d1@null, [EMAIL PROTECTED] ("Chris Anderson") wrote: I tried it, even with the byte length identifer it worked perfectly for me. As a last ditch effort try changing the w to w+. If not then it sounds like a configuration issue for the webserver or php. Dunno what settings though, sorry couldn't be of more help. Thanks for testing. Was that with v4.0.4pl? I'd sure like to know whether there's any possbility it's bug. Seems unlikely, but then again so does the stubborness of frwite() in choosing its own content to write in place of mine. I've pored over phpinfo and php.ini trying to find a config setting that might be causing this weirdness, but so far nothing seems obvious. -- CC -- 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] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14
I am using the latest version of Apache and PHP. Sorry I couldn't be of more help. - Original Message - From: "CC Zona" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, April 17, 2001 3:01 AM Subject: Re: [PHP] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14 In article 012101c0c69b$b01b8d00$8b1412d1@null, [EMAIL PROTECTED] ("Chris Anderson") wrote: I tried it, even with the byte length identifer it worked perfectly for me. As a last ditch effort try changing the w to w+. If not then it sounds like a configuration issue for the webserver or php. Dunno what settings though, sorry couldn't be of more help. Thanks for testing. Was that with v4.0.4pl? I'd sure like to know whether there's any possbility it's bug. Seems unlikely, but then again so does the stubborness of frwite() in choosing its own content to write in place of mine. I've pored over phpinfo and php.ini trying to find a config setting that might be causing this weirdness, but so far nothing seems obvious. -- CC -- 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 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] fwrite not writing
This function suddenly stopped working, and I just can't seem to figure out why. The only change made recently is that now the value of $force at calltime is sometimes true instead of being undefined or null. build_file("file_content","/path/to/file.inc","w",TRUE); function build_file($func_name,$filepath,$mode="w",$force=FALSE) { if($force or !file_exists($filepath) or !filesize($filepath)) //echo filesize($filepath) shows '0' { $content=$func_name(); //echo $content shows it's all there $fp=fopen($filepath,$mode); fwrite($fp,$content); rewind($fp); #temp test $read_back=fread($fp,10); #temp test echo "pfile content:/p\n $read_back"; #temp test, displays nothing fclose($fp); } } I've tried putting echoes and "or die('Error on __LINE__')" on every line, checked all the variable values, and found no answers from that. Everything shows exactly as it should be except that the content that echoes out so nicely *doesn't ever get written to the file*. The function runs to the end without error and the file's modification date is even updated. But the file remains empty. I'm probably missing something ridiculously obvious, but would someone please be kind enough to point out what it is? Thank you!! What is this: !filesize($filepath) If filesize is zero (which it is groan), then do the rest (which it does--except the content it fetches never makes it into the file it writes to. How that can be, I dunno, but that apparently is what it's doing...) Add this above your if loop: $filesize = filesize($filepath); echo $filesize; Already tried echoing that and all the other values. Filesize is 0. That might be causing your loop not to execute...if not, I'm not sure what's wrong. I don't get it. It should work. It did work. Suddenly it's not. -- CC -- 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] fwrite not writing
Ahhh, I see what's going on now. I had more time to read over the code, so now I see what you are trying to do. I'm not sure why it suddenly stopped working, but let's see if you actually need it to work. First of all, I take it that you have content which you want to write into a file. Correct? If so, why does it matter if the file you want to write it to has data anyway? If you are just going to add data into it, isn't it ok that it is a zerolength file? Or is the problem that the file is _not_ actually zerolength, but PHP says it's zerolength anyway? Just try removing the !filesize() part, and then try executing the function. But maybe I just don't understand what you are trying to write and why. Could you be a little more specific what data is being saved in the file, and what is in the file already? -- Plutarck Should be working on something... ...but forgot what it was. "CC Zona" [EMAIL PROTECTED] wrote in message 9bebi3$133$[EMAIL PROTECTED]">news:9bebi3$133$[EMAIL PROTECTED]... This function suddenly stopped working, and I just can't seem to figure out why. The only change made recently is that now the value of $force at calltime is sometimes true instead of being undefined or null. build_file("file_content","/path/to/file.inc","w",TRUE); function build_file($func_name,$filepath,$mode="w",$force=FALSE) { if($force or !file_exists($filepath) or !filesize($filepath)) //echo filesize($filepath) shows '0' { $content=$func_name(); //echo $content shows it's all there $fp=fopen($filepath,$mode); fwrite($fp,$content); rewind($fp); #temp test $read_back=fread($fp,10); #temp test echo "pfile content:/p\n $read_back"; #temp test, displays nothing fclose($fp); } } I've tried putting echoes and "or die('Error on __LINE__')" on every line, checked all the variable values, and found no answers from that. Everything shows exactly as it should be except that the content that echoes out so nicely *doesn't ever get written to the file*. The function runs to the end without error and the file's modification date is even updated. But the file remains empty. I'm probably missing something ridiculously obvious, but would someone please be kind enough to point out what it is? Thank you!! What is this: !filesize($filepath) If filesize is zero (which it is groan), then do the rest (which it does--except the content it fetches never makes it into the file it writes to. How that can be, I dunno, but that apparently is what it's doing...) Add this above your if loop: $filesize = filesize($filepath); echo $filesize; Already tried echoing that and all the other values. Filesize is 0. That might be causing your loop not to execute...if not, I'm not sure what's wrong. I don't get it. It should work. It did work. Suddenly it's not. -- CC -- 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 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] fwrite not writing
In article 9bejks$gl6$[EMAIL PROTECTED], [EMAIL PROTECTED] ("Plutarck") wrote: I'm not sure why it suddenly stopped working, but let's see if you actually need it to work. First of all, I take it that you have content which you want to write into a file. Correct? If so, why does it matter if the file you want to write it to has data anyway? If you are just going to add data into it, isn't it ok that it is a zerolength file? It is needed. I have a dynamically generated page. Most of the content needs to be re-generated with every request. But some of it needs to be re-generated far less often. Rather than unnecessarily hit the db every time to get the exact same content, that content gets cached to an include file. This function checks whether that file needs to get a content refresh, and if so rewrites that content. (I'm not adding data to the file, I'm overwriting it.) Or is the problem that the file is _not_ actually zerolength, but PHP says it's zerolength anyway? Nope, it's really zero length. The filesystem agrees with PHP, and when I open it in a text editor the file is empty. Just try removing the !filesize() part, and then try executing the function. I commented out the entire if() condition, it makes no difference. Maybe I have not made this clear enough: the problem is not in getting inside the loop. The function *is* executing the loop, and *is* reaching the fwite() line as well as continuing without error past that line. The frustrating part is that fwrite() is writing an empty string to the file instead of using the $content variable (which, when echoed immediately before that line, is definitely not empty/null). But maybe I just don't understand what you are trying to write and why. Could you be a little more specific what data is being saved in the file, and what is in the file already? Sometimes the file has data, sometimes it doesn't; sometimes the file exists, sometimes it does. Right now, unfortunately, the file remains empty. I'm trying to fill it with a large block of dynamically generated HTML which will then be used as a static include file for current and subsequent requests. "CC Zona" [EMAIL PROTECTED] wrote in message 9bebi3$133$[EMAIL PROTECTED]">news:9bebi3$133$[EMAIL PROTECTED]... This function suddenly stopped working, and I just can't seem to figure out why. The only change made recently is that now the value of $force at calltime is sometimes true instead of being undefined or null. build_file("file_content","/path/to/file.inc","w",TRUE); function build_file($func_name,$filepath,$mode="w",$force=FALSE) { if($force or !file_exists($filepath) or !filesize($filepath)) //echo filesize($filepath) shows '0' { $content=$func_name(); //echo $content shows it's all there $fp=fopen($filepath,$mode); fwrite($fp,$content); rewind($fp); #temp test $read_back=fread($fp,10); #temp test echo "pfile content:/p\n $read_back"; #temp test, displays nothing fclose($fp); } } I've tried putting echoes and "or die('Error on __LINE__')" on every line, checked all the variable values, and found no answers from that. Everything shows exactly as it should be except that the content that echoes out so nicely *doesn't ever get written to the file*. The function runs to the end without error and the file's modification date is even updated. But the file remains empty. I'm probably missing something ridiculously obvious, but would someone please be kind enough to point out what it is? Thank you!! What is this: !filesize($filepath) If filesize is zero (which it is groan), then do the rest (which it does--except the content it fetches never makes it into the file it writes to. How that can be, I dunno, but that apparently is what it's doing...) Add this above your if loop: $filesize = filesize($filepath); echo $filesize; Already tried echoing that and all the other values. Filesize is 0. That might be causing your loop not to execute...if not, I'm not sure what's wrong. I don't get it. It should work. It did work. Suddenly it's not. -- CC -- 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] fwrite not writing
if($force or !file_exists($filepath) or !filesize($filepath)) May I suggest if ($force || (!file_exists($filepath)) || (!filesize($filepath))) Probably won't make much difference, but I've never used the "or" clause and cannot vouch for it's effectiveness. Also, put a check in after the fopen() call and make sure you're able to open up the file correctly. Perhaps and fflush() call before the rewind() call to ensure that the file buffer's actually written to disk before you try to re-read it? 'Luck -Szii - Original Message - From: CC Zona [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, April 16, 2001 12:06 PM Subject: Re: [PHP] fwrite not writing In article 9bejks$gl6$[EMAIL PROTECTED], [EMAIL PROTECTED] ("Plutarck") wrote: I'm not sure why it suddenly stopped working, but let's see if you actually need it to work. First of all, I take it that you have content which you want to write into a file. Correct? If so, why does it matter if the file you want to write it to has data anyway? If you are just going to add data into it, isn't it ok that it is a zerolength file? It is needed. I have a dynamically generated page. Most of the content needs to be re-generated with every request. But some of it needs to be re-generated far less often. Rather than unnecessarily hit the db every time to get the exact same content, that content gets cached to an include file. This function checks whether that file needs to get a content refresh, and if so rewrites that content. (I'm not adding data to the file, I'm overwriting it.) Or is the problem that the file is _not_ actually zerolength, but PHP says it's zerolength anyway? Nope, it's really zero length. The filesystem agrees with PHP, and when I open it in a text editor the file is empty. Just try removing the !filesize() part, and then try executing the function. I commented out the entire if() condition, it makes no difference. Maybe I have not made this clear enough: the problem is not in getting inside the loop. The function *is* executing the loop, and *is* reaching the fwite() line as well as continuing without error past that line. The frustrating part is that fwrite() is writing an empty string to the file instead of using the $content variable (which, when echoed immediately before that line, is definitely not empty/null). But maybe I just don't understand what you are trying to write and why. Could you be a little more specific what data is being saved in the file, and what is in the file already? Sometimes the file has data, sometimes it doesn't; sometimes the file exists, sometimes it does. Right now, unfortunately, the file remains empty. I'm trying to fill it with a large block of dynamically generated HTML which will then be used as a static include file for current and subsequent requests. "CC Zona" [EMAIL PROTECTED] wrote in message 9bebi3$133$[EMAIL PROTECTED]">news:9bebi3$133$[EMAIL PROTECTED]... This function suddenly stopped working, and I just can't seem to figure out why. The only change made recently is that now the value of $force at calltime is sometimes true instead of being undefined or null. build_file("file_content","/path/to/file.inc","w",TRUE); function build_file($func_name,$filepath,$mode="w",$force=FALSE) { if($force or !file_exists($filepath) or !filesize($filepath)) file://echo filesize($filepath) shows '0' { $content=$func_name(); file://echo $content shows it's all there $fp=fopen($filepath,$mode); fwrite($fp,$content); rewind($fp); #temp test $read_back=fread($fp,10); #temp test echo "pfile content:/p\n $read_back"; #temp test, displays nothing fclose($fp); } } I've tried putting echoes and "or die('Error on __LINE__')" on every line, checked all the variable values, and found no answers from that. Everything shows exactly as it should be except that the content that echoes out so nicely *doesn't ever get written to the file*. The function runs to the end without error and the file's modification date is even updated. But the file remains empty. I'm probably missing something ridiculously obvious, but would someone please be kind enough to point out what it is? Thank you!! What is this: !filesize($filepath) If filesize is zero (which it is groan), then do the rest (which it does--except the content it fetches never makes it into the file it writes to. How that can be, I dunno, but that apparently is what it's doing...) Add this above your if loop: $filesize = filesize($filepath); echo $filesize; Already tried echoing that and all the other va
[PHP] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14
Suggestions so far have focused on parts of the function other than fwrite, so I'm trying again with a stripped-down example. After spending many hours trying to make this very simple function work again, I'm beginning to think fwrite in broken--either in 4.0.4pl1 (?!) or in my build of it (it was working fine before...). Before filing a bug report, would a few people test whether this fails to write on their system too? Thank you! function build_file() { $fp=fopen("/path/to/directory/test.inc","w") or die("ERROR on fopen" . $php_errormsg); fwrite($fp,"pHi, I'm some test content/p",1) or die("ERROR: fwrite " . $php_errormsg); fclose($fp) or die("ERROR: fclose" . $php_errormsg); } build_file(); //no errors and file modification date is updated echo "pBegin include...p"; //ok include("/path/to/directory/test.inc"); //NOTHING! echo "p...End includep"; //ok (Checking from the commandline, the file is definitely being set to empty. It's writing an empty string to the file instead of writing the specified content.) -- CC -- 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] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14
Have you checked the following things: A) if the file is actually there? B)Is it an include error C)Do you have the required permissions for write access and for including from that directory? - Original Message - From: "CC Zona" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, April 16, 2001 5:34 PM Subject: [PHP] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14 Suggestions so far have focused on parts of the function other than fwrite, so I'm trying again with a stripped-down example. After spending many hours trying to make this very simple function work again, I'm beginning to think fwrite in broken--either in 4.0.4pl1 (?!) or in my build of it (it was working fine before...). Before filing a bug report, would a few people test whether this fails to write on their system too? Thank you! function build_file() { $fp=fopen("/path/to/directory/test.inc","w") or die("ERROR on fopen" . $php_errormsg); fwrite($fp,"pHi, I'm some test content/p",1) or die("ERROR: fwrite " . $php_errormsg); fclose($fp) or die("ERROR: fclose" . $php_errormsg); } build_file(); //no errors and file modification date is updated echo "pBegin include...p"; //ok include("/path/to/directory/test.inc"); //NOTHING! echo "p...End includep"; //ok (Checking from the commandline, the file is definitely being set to empty. It's writing an empty string to the file instead of writing the specified content.) -- CC -- 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 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] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14
In article 002b01c0c697$9628ee00$8b1412d1@null, [EMAIL PROTECTED] ("Chris Anderson") wrote: Have you checked the following things: A) if the file is actually there? Yes. (And even when the file is not there, fopen() correctly re-creates it. And fwrite continued to write the wrong--empty--string to it.) B)Is it an include error Checked, and no. The file is being included. It just doesn't have any content to display. C)Do you have the required permissions for write access and for including from that directory? Permissions: yes (the file is updating, just with the wrong content) Including: yes (it's in the include path too) I've also checked that no other fuction is writing to the same file and that the function is not recursing (to, say, write the correct content on one pass then overwrite with empty string on the next pass). No to those too. - Original Message - From: "CC Zona" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, April 16, 2001 5:34 PM Subject: [PHP] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14 Suggestions so far have focused on parts of the function other than fwrite, so I'm trying again with a stripped-down example. After spending many hours trying to make this very simple function work again, I'm beginning to think fwrite in broken--either in 4.0.4pl1 (?!) or in my build of it (it was working fine before...). Before filing a bug report, would a few people test whether this fails to write on their system too? Thank you! function build_file() { $fp=fopen("/path/to/directory/test.inc","w") or die("ERROR on fopen" . $php_errormsg); fwrite($fp,"pHi, I'm some test content/p",1) or die("ERROR: fwrite " . $php_errormsg); fclose($fp) or die("ERROR: fclose" . $php_errormsg); } build_file(); //no errors and file modification date is updated echo "pBegin include...p"; //ok include("/path/to/directory/test.inc"); //NOTHING! echo "p...End includep"; //ok (Checking from the commandline, the file is definitely being set to empty. It's writing an empty string to the file instead of writing the specified content.) -- CC -- 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] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14
come to think of it, why are you passing 3 arguements to fwrite()? - Original Message - From: "CC Zona" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, April 16, 2001 5:34 PM Subject: [PHP] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14 Suggestions so far have focused on parts of the function other than fwrite, so I'm trying again with a stripped-down example. After spending many hours trying to make this very simple function work again, I'm beginning to think fwrite in broken--either in 4.0.4pl1 (?!) or in my build of it (it was working fine before...). Before filing a bug report, would a few people test whether this fails to write on their system too? Thank you! function build_file() { $fp=fopen("/path/to/directory/test.inc","w") or die("ERROR on fopen" . $php_errormsg); fwrite($fp,"pHi, I'm some test content/p",1) or die("ERROR: fwrite " . $php_errormsg); fclose($fp) or die("ERROR: fclose" . $php_errormsg); } build_file(); //no errors and file modification date is updated echo "pBegin include...p"; //ok include("/path/to/directory/test.inc"); //NOTHING! echo "p...End includep"; //ok (Checking from the commandline, the file is definitely being set to empty. It's writing an empty string to the file instead of writing the specified content.) -- CC -- 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 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] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14
alright try removing the byte length identifier - Original Message - From: "Chris Anderson" [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, April 16, 2001 1:20 PM Subject: Re: [PHP] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14 come to think of it, why are you passing 3 arguements to fwrite()? - Original Message - From: "CC Zona" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, April 16, 2001 5:34 PM Subject: [PHP] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14 Suggestions so far have focused on parts of the function other than fwrite, so I'm trying again with a stripped-down example. After spending many hours trying to make this very simple function work again, I'm beginning to think fwrite in broken--either in 4.0.4pl1 (?!) or in my build of it (it was working fine before...). Before filing a bug report, would a few people test whether this fails to write on their system too? Thank you! function build_file() { $fp=fopen("/path/to/directory/test.inc","w") or die("ERROR on fopen" . $php_errormsg); fwrite($fp,"pHi, I'm some test content/p",1) or die("ERROR: fwrite " . $php_errormsg); fclose($fp) or die("ERROR: fclose" . $php_errormsg); } build_file(); //no errors and file modification date is updated echo "pBegin include...p"; //ok include("/path/to/directory/test.inc"); //NOTHING! echo "p...End includep"; //ok (Checking from the commandline, the file is definitely being set to empty. It's writing an empty string to the file instead of writing the specified content.) -- CC -- 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 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 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] fwrite not writing (simpler example), PHP 4.0.4pl1, Apache/1.3.14
In article 006701c0c699$ad65cdc0$8b1412d1@null, [EMAIL PROTECTED] ("Chris Anderson") wrote: come to think of it, why are you passing 3 arguements to fwrite()? Whoops! That's a typo left over from the last round of tests, adding every optional argument just in case something wasn't really optional. Of course the third argument actually belongs to fopen(). Though it shouldn't be needed there either. (And yup, I just double-checked and it doesn't work without the typo either. sigh) -- CC -- 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] fwrite not writing
This function suddenly stopped working, and I just can't seem to figure out why. The only change made recently is that now the value of $force at calltime is sometimes true instead of being undefined or null. build_file("file_content","/path/to/file.inc","w",TRUE); function build_file($func_name,$filepath,$mode="w",$force=FALSE) { if($force or !file_exists($filepath) or !filesize($filepath)) //echo filesize($filepath) shows '0' { $content=$func_name(); //echo $content shows it's all there $fp=fopen($filepath,$mode); fwrite($fp,$content); rewind($fp); #temp test $read_back=fread($fp,10); #temp test echo "pfile content:/p\n $read_back"; #temp test, displays nothing fclose($fp); } } I've tried putting echoes and "or die('Error on __LINE__')" on every line, checked all the variable values, and found no answers from that. Everything shows exactly as it should be except that the content that echoes out so nicely *doesn't ever get written to the file*. The function runs to the end without error and the file's modification date is even updated. But the file remains empty. I'm probably missing something ridiculously obvious, but would someone please be kind enough to point out what it is? Thank you!! -- CC -- 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] fwrite()
I have a textarea and I want to save the textarea text into a file. Then I put this in the html: INPUT NAME="arqcliente" TYPE="file" And this in action of php: $fd = fopen("Augusto.wri", "w" ); fwrite($fd, $conteudo); fclose( $fd ); But I'm having a big problem on this. Is the text has this caracter ("), the PHP add "\" before. So the number of (\) double every time that I want to update the file via textarea. How can I solve this problem? regards, Augusto -- 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] fwrite()
Check out .htmlspecialchars(..) .removeslashes() .stripslashes() - Richard "Augusto Cesar Castoldi" [EMAIL PROTECTED] wrote in message Pine.GSO.4.10.10104062012140.20277-10@venus">news:Pine.GSO.4.10.10104062012140.20277-10@venus... I have a textarea and I want to save the textarea text into a file. Then I put this in the html: INPUT NAME="arqcliente" TYPE="file" And this in action of php: $fd = fopen("Augusto.wri", "w" ); fwrite($fd, $conteudo); fclose( $fd ); But I'm having a big problem on this. Is the text has this caracter ("), the PHP add "\" before. So the number of (\) double every time that I want to update the file via textarea. How can I solve this problem? regards, Augusto -- 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 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] fwrite()
simply add: $conteudo = stripslashes($conteudo) -- 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] fwrite in PHP4
This script works properly under PHP 3.0.18, but in PHP 4.0.4pl1 is the result file empty. When I add commented line #2 instead of calling MyEcho, it works correctly. When I add lines #1, it works somehow strange. After fwrite and fclose is file empty and after second fopen (and no fwrite) "OK" appears in it. What am I doing wrong? ? function MyEcho($Text) { global $GlPOutputFile, $GlOutputFile; fwrite($GlPOutputFile, $Text); #1 fclose($GlPOutputFile); #1 copy($GlOutputFile, "after_write"); #1 $GlPOutputFile=fopen($GlOutputFile, 'a'); } { $GlOutputFile=uniqid("/tmp/").".tmp"; $GlPOutputFile=fopen($GlOutputFile, "w"); MyEcho("OK"); #2 fwrite($GlPOutputFile, "OK"); fclose($GlPOutputFile); copy($GlOutputFile, "result"); unlink($GlOutputFile); } ? -- 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]