943,649 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2512
  • PHP RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Aug 29th, 2008
0

Re: Php question

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Aug 29th, 2008
0

Re: Php question

Click to Expand / Collapse  Quote originally posted by R0bb0b ...
php Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
jencinas69 is offline Offline
68 posts
since Nov 2007
Aug 29th, 2008
0

Re: Php question

Click to Expand / Collapse  Quote originally posted by jencinas69 ...
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.
php Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Aug 29th, 2008
0

Re: Php question

Click to Expand / Collapse  Quote originally posted by R0bb0b ...
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.
php Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
jencinas69 is offline Offline
68 posts
since Nov 2007
Aug 29th, 2008
0

Re: Php question

Click to Expand / Collapse  Quote originally posted by jencinas69 ...
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.
php Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Aug 29th, 2008
0

Re: Php question

Click to Expand / Collapse  Quote originally posted by R0bb0b ...
OK, use this then.
php Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
jencinas69 is offline Offline
68 posts
since Nov 2007
Aug 29th, 2008
1

Re: Php question

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.
Reputation Points: 358
Solved Threads: 89
Posting Shark
R0bb0b is offline Offline
986 posts
since Jun 2008
Aug 29th, 2008
0

Re: Php question

Click to Expand / Collapse  Quote originally posted by R0bb0b ...
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
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
jencinas69 is offline Offline
68 posts
since Nov 2007
Sep 2nd, 2008
0

Re: Php question

How could I write the content on petsfeed.txt into the new file I am creating wiht the ID Category Description headers?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
jencinas69 is offline Offline
68 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Pagination help. Desperate
Next Thread in PHP Forum Timeline: Newbie PHP / MySQL Question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC