#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    7
    Rep Power
    0

    File_put_contents


    Have executed this code on two separate servers, one windows and one unix:

    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    echo 
    '<br>start of test';
    file_put_contents('xxx.html','Hello');
    echo 
    '<br>end of test';
    ?>
    In both cases, the only display was:

    start of test

    Please advise me what is wrong with this code.

    Thanks,
    Roger
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    There is nothing wrong with that exact code that you have posted.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    7
    Rep Power
    0
    requinix-

    Good, but then, why does it abend before issuing end of test, and fail to write a string to the destination file, and fail to issue an error message, on two different types of server, no less?

    Thanks,

    Roger
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    Because there's something else wrong.

    You may have your error_reporting set, but how about display_errors?
    PHP Code:
    <?php 
    error_reporting
    (E_ALL); 
    ini_set('display_errors'true);
    echo 
    '<br>start of test'
    file_put_contents('xxx.html','Hello'); 
    echo 
    '<br>end of test'
    ?>
    And to be sure, that is your exact code?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    7
    Rep Power
    0
    Yes, or at least it was. Based on your observation, I have added to it:

    PHP Code:
    <?php
    error_reporting
    (E_ALL);
    ini_set("display_errors"1); 
    echo 
    '<br>start of test';
    file_put_contents('xxx.html','Hello');
    echo 
    '<br>end of test';
    ?>
    And now get the following display, once again on both servers:


    start of test
    Fatal error: Call to undefined function: file_put_contents() in /var/www/html/test/test_file_put_contents.php on line 5
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,972
    Rep Power
    375
    you must be using a php version < 5 as per the manual:

    http://php.net/manual/en/function.file-put-contents.php

    a question about file_put_contents,

    why doesnt it create a directory if that doesnt exist? it creates the file but i would expect it to create the directory too.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    7
    Rep Power
    0
    requinix and Paul-

    Have changed to use fopen, fwrite, fclose, and it works fine now.

    Many thanks,

    Roger
  14. #8
  15. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    If you're actually using PHP 4, then you're far, far away from "It works".
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    51
    Rep Power
    2
    Originally Posted by Taxon
    start of test
    Fatal error: Call to undefined function: file_put_contents() in /var/www/html/test/test_file_put_contents.php on line 5
    eek, still on PHP4?
    Last edited by freak.inside; September 19th, 2013 at 04:57 AM.
    All generalizations are false, including this one. Free hosting

IMN logo majestic logo threadwatch logo seochat tools logo