rauljr7
By:
rauljr7

fopen in php doesn't work

April 4, 2018 135 views
Apache PHP Ubuntu 16.04

Hello! When I try a simple fopen("hello.txt", "w") it doesn't do anything at all. I changed to full permissions 777 and changed around the owner to root and different ones and nothing. I added var_dump and echoed the fopen and it gives me False(bool). I checked the fopen configuration in the php.ini file and it is enabled. Any help??

3 Answers

What are you trying to do?

The "w" in fopen("hello.txt","w") means to write to a file, not read.
It would be best to read the PHP documentation on fopen().

http://php.net/manual/en/function.fopen.php

Lots of examples!
Hope that helps, let me know if I can help more.

  • Yes I am trying to save a new file. It does let me read and edit files that are already created but not create a file

  • The code was as simple as:

    $handle = fopen('empty.txt', 'w');
    fclose($handle);

    And I logged in to another hosting provider siteground just to see if there was a difference and it worked fine there so I'm not sure if it's some setup in my server or something.

    • The above code would actually not produce any output.

      $handle = fopen('empty.txt','w');
      This line opens the file empty.txt for writing. So you're telling PHP you want to write inforamtion to the file.

      fclose($handle); This line closes the file. You didn't write or read anything from the file named empty.txt.

SO ALL U HAV TOO DOO IZ GO TO MI HOWS AND THEN ASK ME YOUR KWESTCHON AND I WIL TEL U

Have another answer? Share your knowledge.