Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Question [Need] help with file_put_contents()

    I keep getting this message:

    Fatal error: Call to undefined function: file_put_contents() in /home/content/m/a/t/matafy2/html/wp-content/themes/WPStore/library/includes/admin_notification_edit.php on line 17

    PHP Code:
    <?php
    global $wpdb;
    if(
    $_POST)
    {
        
    $subject $_POST['subject'];
        
    $message $_POST['message'];
        
    $filename $_POST['filename'];
        
    $file $_POST['notification'];    
        if(
    $file=='emails' || $file=='message')
        {
            
    $destinationfile =   ABSPATH "wp-content/uploads/notification/$file/$filename";
            if(
    $subject)
            {
                
    $subject '[SUBJECT-STR]'.$subject.'[SUBJECT-END]';
            }
            echo 
    $message $subject.$message;
            
    file_put_contents($destinationfile,$message); #-- Line 17 --#
            
            
    $fp fopen($destinationfile,'rw');
            
    wp_redirect(get_option('siteurl').'/wp-admin/admin.php?page=notification&msg=success');
        }
    }
    ?>
    I know it has to do with PHP5 and I believe I have PHP4 installed on my server, but how do I fix it?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You use fopen instead. Change this
    PHP Code:
    echo $message $subject.$message;
            
    file_put_contents($destinationfile,$message); #-- Line 17 --#
            
            
    $fp fopen($destinationfile,'rw'); 
    to this
    PHP Code:
    $message $subject.$message;
    echo 
    $message;
            
    $fp fopen($destinationfile,'w+');
            if(
    $fp)
    {
    fwrite($fp,$message);
    fclose($fp);
    }
    else
    {
    echo 
    'failed to open '.$destinationfile;

    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    matafy (06-30-2010)

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    59
    Thanks
    13
    Thanked 0 Times in 0 Posts
    Thank you! it worked perfectly.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •