...

View Full Version : [Need] help with file_put_contents()



matafy
06-30-2010, 09:33 AM
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
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?

_Aerospace_Eng_
06-30-2010, 09:39 AM
You use fopen instead. Change this

echo $message = $subject.$message;
file_put_contents($destinationfile,$message); #-- Line 17 --#

$fp = fopen($destinationfile,'rw');
to this

$message = $subject.$message;
echo $message;
$fp = fopen($destinationfile,'w+');
if($fp)
{
fwrite($fp,$message);
fclose($fp);
}
else
{
echo 'failed to open '.$destinationfile;
}

matafy
06-30-2010, 10:04 AM
Thank you! it worked perfectly.:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum