Jump to content
xisto Community
Sign in to follow this  
electriic ink

Error When Using file_put_contents() failed to call to undefined function

Recommended Posts

Hey all, I decided to write a script which writes some text to a file, but I have a problem when I execute the script, I get a fatal error:

 

Fatal error: Call to undefined function: file_put_contents() in /home/cmatcme/public_html/afile.php on line 55

This is the code I'm using to write the file:

 

$ipfnsdoc = "/home/cmatcme/public_html/afolder/afile.txt";  if (!is_readable($ipfnsdoc)) {     echo "File cannot be read";     $stopload = 1; } if  (!is_writable($ipfnsdoc)) {     echo "<br>\nFile cannot be written to";     $stopload = 1; }  if (!$stopload == 1) {      $da_contents = file_get_contents($ipfnsdoc);     if ($da_contents == NULL) {       $da_contents = 0;     }     $towrite = $da_contents + 1;      [color=blue]<span style='font-size:10pt;line-height:100%'>file_put_contents($ipfnsdoc,$towrite);[/color]</span> }

I've read php.net's documentation on the function and to be honest, I can't understand half of it, so can anyone please tell me what I'm doing wrong?

Share this post


Link to post
Share on other sites

First check that you have CHMOD 777 to the file and the folder it is in, which often requires moving it to a different folder of its own. There may also be a problem with the path /home/cmatcme/public_html/afolder/afile.txt As far as I am aware, if the PHP script is in /home/cmatcme/public_html/afolder/ then you would write the path as just afile.txtI think it works just like HTML paths. You never put the literal file path in HTML, so you don't in PHP. Try changing it and see if it helps. It doesn't matter that you don't understand the docs :) , you don't need to. You are using the function correctly as it is.

Share this post


Link to post
Share on other sites

Both the directory "afolder" and the file "afile.txt" are have 777 permissions. The file has the full url set because it's part of a page header file and so will be included in all files which will be in many different directories. Seeing as I don't have any subdomains or folders which require the inclusion of this file yet I'm gonna try anyway :)======No luck :D Same error. I know the file exists and permissions are set because if they weren't is_readable() and is_writable() would pick those errors up.The contents of $towrite before it is set to be written into afile.txt is 1 and $ipfnsdoc should be the same as when it was set earlier on (afolder/afile.txt). I'm glad I've used the function correctly but also confused because if I am, how comes the error has arisen?

Share this post


Link to post
Share on other sites

I think i know what the problem is. I looked up file_put_contents, and it said it's only for php5+, and i dont think Xisto has that version installed. I think Xisto has v4.3.x. That's why you've been getting errors. You'll have to do it the old fashion way, with fopen, fwrite, and fclose.

Share this post


Link to post
Share on other sites

That's probably it. I've tried using the fopen(), fwrite() and fclose() procedure and it works. Thank you truefusion and rvalkass for helping me ;). //Locked

Share this post


Link to post
Share on other sites
Fixed itError When Using file_put_contents()

Add this code on top files

<?php

if(!function_exists('file_put_contents')) {   function file_put_contents($filename, $data, $file_append = false) {   $fp = fopen($filename, (!$file_append ? 'w+' : 'a+'));   if(!$fp) {   trigger_error('file_put_contents cannot write in file.', E_USER_ERROR);   return;   }   fputs($fp, $data);   fclose($fp);   }  }    ?>

-reply by viethakKeywords: fatal error: call to undefined function: file_put_contents()

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.