Title: fgets()-error
Last modified: February 28, 2023

---

# fgets()-error

 *  Resolved [Matta Cib](https://wordpress.org/support/users/matta-cib/)
 * (@matta-cib)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/fgets-error/)
 * Hello,
   First of all, thank you for the plugin WPCode Lite!I am asking for help
   with the following problem. The PHP code below does not work:$fp = fopen(“current/
   yesterday.txt”, “r+”); //contains numeric value like 123456789123$yesterday =
   fgets($fp, 9);echo “$yesterday”;I get the following error message (which I don’t
   know what to do with):“Snippet not activated, the following error was encountered:**
   fgets(): Argument #1 ($stream) must be of type resource, bool given**“I have 
   already used this code in a previously created snippet and this snippet still
   works fine. However, if I try to create a new snippet with the same code, I get
   the above error message.Can it be because I have meanwhile increased the PHP 
   version to 8.0.28? And if so, what to do? (I’m using WP 6.1.1)Thanks and best
   regardsMatta
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ffgets-error%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/fgets-error/#post-16515986)
 * Hi Matta,
 * It sounds like the error you are getting is that the fopen command can’t open
   the file you are pointing it to. From the [documentation](https://www.php.net/manual/en/function.fopen.php),
   fopen will return false if that pointer can’t be opened.
 * I think you may need to use full path to the .txt file you are targeting.
 *  Thread Starter [Matta Cib](https://wordpress.org/support/users/matta-cib/)
 * (@matta-cib)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/fgets-error/#post-16516447)
 * Hello Mircea,
 * Thanks for your answer and the tip. But even with the complete, absolute path
   it doesn’t work…
   An “old” snippet, which is existing for a long time, works flawlessly
   online. And that is strange. This actually speaks against the possibility that
   the problem occurs due to a changed PHP version, because then an “old” snippet
   that contains this code should no longer work.I therefore rather suspect that
   the problem is due to a change within WPCode Lite, because there the activation
   of the snippet with said error message is prevented – the execution of the code
   in a previously saved and uploaded snippet works.Thanks and best regardsmatta
 *  Plugin Author [Mircea Sandu](https://wordpress.org/support/users/gripgrip/)
 * (@gripgrip)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/fgets-error/#post-16516914)
 * Hi Matta,
 * WPCode simply catches the error thrown by PHP and it prevents the activation 
   of the snippet + forwards the message to you so you can see what prevented the
   snippet from being activated.
 * If the snippet would get activated your site would throw the same fatal error.
   You can try adding a check before the fgets call to prevent the error in case
   you suspect that the issue only happens during activation, it would e good to
   have a check in any case to prevent the error and instead display a message or
   something similar when the file cannot be accessed.
 * Another thing to consider is if your file has the right permissions to be accessed
   by the PHP script you are using.
 *  Thread Starter [Matta Cib](https://wordpress.org/support/users/matta-cib/)
 * (@matta-cib)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/fgets-error/#post-16576390)
 * Hello Mircea,
   Thank you very much for your answer! For my part, I’m only replying
   today, because (to be honest) I didn’t understand your answer and hired a PHP
   specialist, and he has now found the error: Your hint about the absolute path
   was already correct, but I had entered the absolute path of the URL, but it must
   correctly be the absolute path of the root directory where the corresponding 
   file is located. But now the problem is solved 🙂Best regardsMatta

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘fgets()-error’ is closed to new replies.

 * ![](https://ps.w.org/insert-headers-and-footers/assets/icon-256x256.png?rev=2758516)
 * [WPCode - Insert Headers and Footers + Custom Code Snippets - WordPress Code Manager](https://wordpress.org/plugins/insert-headers-and-footers/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-headers-and-footers/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-headers-and-footers/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-headers-and-footers/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-headers-and-footers/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 4 replies
 * 2 participants
 * Last reply from: [Matta Cib](https://wordpress.org/support/users/matta-cib/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/fgets-error/#post-16576390)
 * Status: resolved