Php question

Reply

Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Php question

 
0
  #21
Aug 29th, 2008
  1. <?php
  2.  
  3. error_reporting(E_ALL ^ E_NOTICE);
  4. ini_set("display_errors", true);
  5.  
  6.  
  7. $file = "pets_feed_" . date("Ymd") . ".txt";// - for yyyymmdd
  8.  
  9. if (!file_exists($file)) touch($file);
  10.  
  11. $fh = fopen($file, "r");
  12.  
  13. $fcontent = fread($fh, filesize($file));
  14.  
  15. $towrite = "ID Category Description"."\n";
  16.  
  17.  
  18.  
  19. $fh22 = fopen($file, 'w+');
  20.  
  21. fwrite($fh22, $towrite . $fcontent);
  22.  
  23. fclose($fh);
  24.  
  25. fclose($fh22);
  26.  
  27. ?>
Last edited by R0bb0b; Aug 29th, 2008 at 4:04 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 68
Reputation: jencinas69 is an unknown quantity at this point 
Solved Threads: 1
jencinas69's Avatar
jencinas69 jencinas69 is offline Offline
Junior Poster in Training

Re: Php question

 
0
  #22
Aug 29th, 2008
Originally Posted by R0bb0b View Post
  1. <?php
  2.  
  3. error_reporting(E_ALL ^ E_NOTICE);
  4. ini_set("display_errors", true);
  5.  
  6.  
  7. $file = "pets_feed_" . date("Ymd") . ".txt";// - for yyyymmdd
  8.  
  9. if (!file_exists($file)) touch($file);
  10.  
  11. $fh = fopen($file, "r");
  12.  
  13. $fcontent = fread($fh, filesize($file));
  14.  
  15. $towrite = "ID Category Description"."\n";
  16.  
  17.  
  18.  
  19. $fh22 = fopen($file, 'w+');
  20.  
  21. fwrite($fh22, $towrite . $fcontent);
  22.  
  23. fclose($fh);
  24.  
  25. fclose($fh22);
  26.  
  27. ?>

I get this error

Warning: fread() [function.fread]: Length parameter must be greater than 0 in /var/www/html/yumasun/media/gadzoo/txt.php on line 13
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Php question

 
0
  #23
Aug 29th, 2008
Originally Posted by jencinas69 View Post
I get this error

Warning: fread() [function.fread]: Length parameter must be greater than 0 in /var/www/html/yumasun/media/gadzoo/txt.php on line 13
Your getting that because the file was just created so file size = 0. This doesn't mean it's not working it's just letting you know that fread won't read anything because there is nothing to read yet. Let me make one adjustment.

This should clear that up.
  1. <?php
  2.  
  3. error_reporting(E_ALL ^ E_NOTICE);
  4. ini_set("display_errors", true);
  5.  
  6.  
  7. $file = "pets_feed_" . date("Ymd") . ".txt";// - for yyyymmdd
  8.  
  9. if (!file_exists($file)) touch($file);
  10.  
  11. $fh = fopen($file, "r");
  12. $fcontent = "";
  13. if(filesize($file) > 0)
  14. {
  15. $fcontent = fread($fh, filesize($file));
  16. }
  17.  
  18. $towrite = "ID Category Description"."\n";
  19.  
  20.  
  21.  
  22. $fh22 = fopen($file, 'w+');
  23.  
  24. fwrite($fh22, $towrite . $fcontent);
  25.  
  26. fclose($fh);
  27.  
  28. fclose($fh22);
  29.  
  30. ?>
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 68
Reputation: jencinas69 is an unknown quantity at this point 
Solved Threads: 1
jencinas69's Avatar
jencinas69 jencinas69 is offline Offline
Junior Poster in Training

Re: Php question

 
0
  #24
Aug 29th, 2008
Originally Posted by R0bb0b View Post
Your getting that because the file was just created so file size = 0. This doesn't mean it's not working it's just letting you know that fread won't read anything because there is nothing to read yet. Let me make one adjustment.

This should clear that up.
  1. <?php
  2.  
  3. error_reporting(E_ALL ^ E_NOTICE);
  4. ini_set("display_errors", true);
  5.  
  6.  
  7. $file = "pets_feed_" . date("Ymd") . ".txt";// - for yyyymmdd
  8.  
  9. if (!file_exists($file)) touch($file);
  10.  
  11. $fh = fopen($file, "r");
  12. $fcontent = "";
  13. if(filesize($file) > 0)
  14. {
  15. $fcontent = fread($fh, filesize($file));
  16. }
  17.  
  18. $towrite = "ID Category Description"."\n";
  19.  
  20.  
  21.  
  22. $fh22 = fopen($file, 'w+');
  23.  
  24. fwrite($fh22, $towrite . $fcontent);
  25.  
  26. fclose($fh);
  27.  
  28. fclose($fh22);
  29.  
  30. ?>

I dont get the error any more and is writting the file to the server but is only puttting this content

ID Category Description

is suppose to look like this

ID Category Description
456510 P115 JANDAY CONURE Very pretty, green/orange/blue, but keeps telling ME to shut up! $250/obo. 928-555-1212.


Thank you
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Php question

 
0
  #25
Aug 29th, 2008
Originally Posted by jencinas69 View Post
I dont get the error any more and is writting the file to the server but is only puttting this content

ID Category Description

is suppose to look like this

ID Category Description
456510 P115 JANDAY CONURE Very pretty, green/orange/blue, but keeps telling ME to shut up! $250/obo. 928-555-1212.


Thank you
OK, use this then.
  1. <?php
  2.  
  3. error_reporting(E_ALL ^ E_NOTICE);
  4. ini_set("display_errors", true);
  5.  
  6.  
  7. $file = "pets_feed_" . date("Ymd") . ".txt";// - for yyyymmdd
  8.  
  9. if (!file_exists($file)) touch($file);
  10.  
  11. $fh = fopen($file, "r");
  12.  
  13. $fcontent = @fread($fh, filesize($file));
  14.  
  15. $towrite = "ID Category Description"."\n";
  16.  
  17.  
  18.  
  19. $fh22 = fopen($file, 'w+');
  20.  
  21. fwrite($fh22, $towrite . $fcontent);
  22.  
  23. fclose($fh);
  24.  
  25. fclose($fh22);
  26.  
  27. ?>
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 68
Reputation: jencinas69 is an unknown quantity at this point 
Solved Threads: 1
jencinas69's Avatar
jencinas69 jencinas69 is offline Offline
Junior Poster in Training

Re: Php question

 
0
  #26
Aug 29th, 2008
Originally Posted by R0bb0b View Post
OK, use this then.
  1. <?php
  2.  
  3. error_reporting(E_ALL ^ E_NOTICE);
  4. ini_set("display_errors", true);
  5.  
  6.  
  7. $file = "pets_feed_" . date("Ymd") . ".txt";// - for yyyymmdd
  8.  
  9. if (!file_exists($file)) touch($file);
  10.  
  11. $fh = fopen($file, "r");
  12.  
  13. $fcontent = @fread($fh, filesize($file));
  14.  
  15. $towrite = "ID Category Description"."\n";
  16.  
  17.  
  18.  
  19. $fh22 = fopen($file, 'w+');
  20.  
  21. fwrite($fh22, $towrite . $fcontent);
  22.  
  23. fclose($fh);
  24.  
  25. fclose($fh22);
  26.  
  27. ?>
Is doing the same
just writting ID Category Description to the file
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: Php question

 
1
  #27
Aug 29th, 2008
Not for me, I copied that script, refreshed my page about 7 or 8 times and got this in pets_feed_20080829.txt

ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description

which means that it is working fine.
Last edited by R0bb0b; Aug 29th, 2008 at 5:27 pm.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 68
Reputation: jencinas69 is an unknown quantity at this point 
Solved Threads: 1
jencinas69's Avatar
jencinas69 jencinas69 is offline Offline
Junior Poster in Training

Re: Php question

 
0
  #28
Aug 29th, 2008
Originally Posted by R0bb0b View Post
Not for me, I copied that script, refreshed my page about 7 or 8 times and got this in pets_feed_20080829.txt

ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description
ID Category Description

which means that it is working fine.

This is because the file is not re writting to the file is just writting but it needs to write

ID Category Description

and the petsfeed.txt contetn

Thank you
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 68
Reputation: jencinas69 is an unknown quantity at this point 
Solved Threads: 1
jencinas69's Avatar
jencinas69 jencinas69 is offline Offline
Junior Poster in Training

Re: Php question

 
0
  #29
Sep 2nd, 2008
How could I write the content on petsfeed.txt into the new file I am creating wiht the ID Category Description headers?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC