"Fatal error: Call to undefined function: file_put_contents()"

  打开页面时提示这个错误:

Fatal error: Call to undefined function: file_put_contents()

  意思是请求未定义的函数,出现这个提示通常有两种情况:

  1.当前php版本不支持此函数

  2.请求的函数是用户自定义编写,但是找不到这个函数所在的文件

  file_put_contents函数的php支持版本是从5.0开始,见:http://cn2.php.net/manual/zh/function.file-put-contents.php

  查看了一下机器当前php版本是4.4.2,那么就出现第一种情况php版本不支持了,不过就算版本不支持还是可以做下改动让它支持的:

  

define('FILE_APPEND', 1); 

if (!function_exists("file_put_contents")) { 

    function file_put_contents($n, $d, $flag = false) { 
        $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w'; 
        $f = @fopen($n, $mode); 
        if ($f === false) { 
            return 0; 
        } else { 
            if (is_array($d)) $d = implode($d); 
            $bytes_written = fwrite($f, $d); 
            fclose($f); 
            return $bytes_written; 
        } 
    } 

}  

  将这段代码添加到调用file_put_contents函数之前的代码文件中就可以解决问题,重新打开页面就不会出现这个提示。

原文地址:https://www.cnblogs.com/haocool/p/3677127.html