Error with file_put_contents()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moishy
    New Member
    • Oct 2006
    • 104

    Error with file_put_contents()

    When I try to write to file like this:
    [PHP]file_put_conten ts("test.txt"," Hello World");[/PHP]
    I get an error: Fatal error: Call to undefined function: file_put_conten ts()

    File_get_conten ts works perfectly, I can't figure out why I can't write!
    Any help?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Are you absolutely sure there isn't a typo in the function name?

    You could always try going the long way around:
    [code=php]
    $fh = fopen("file.txt ", "wb");
    fwrite($fh, "some text");
    fclose($fh);
    [/code]

    Comment

    • moishy
      New Member
      • Oct 2006
      • 104

      #3
      I am placing the entire contents of my php file:
      [PHP]<?php
      echo file_put_conten ts("test.txt"," Hello World. Testing!");
      ?>[/PHP]
      Instead of returning 21 it returns Fatal error: Call to undefined function: file_put_conten ts() in...

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Moishy.

        file_get_conten ts() was introduced in PHP 4, but file_put_conten ts() is only available in PHP 5. What version are you running?

        Comment

        • moishy
          New Member
          • Oct 2006
          • 104

          #5
          I'm not sure what version I have.
          I am hosted by godaddy.com

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            You could use the phpinfo() function to find out which version you have.

            Just create a new .php file, add the following and navigate to it in a browser. It will bring up every detail on your PHP configuration.
            [code=php]
            <?php
            phpinfo();
            ?>
            [/code]

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, Moishy.

              Have a look at this article.

              Comment

              • moishy
                New Member
                • Oct 2006
                • 104

                #8
                Originally posted by pbmods
                Heya, Moishy.

                Have a look at this article.
                Thanks a lot! You were very helpful!

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #9
                  Heya, Moishy.

                  We aim to please.

                  Good luck with your project, and if you ever need anything, post back anytime :)

                  Comment

                  • shrimpwagon
                    New Member
                    • Jul 2012
                    • 1

                    #10
                    I know this is an old post but I just wanted to clear this up. GoDaddy doesn't offer file_put_conten ts() for PHP5 hosting. I had to use fwrite(). Thanks Atli.

                    Comment

                    Working...