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

  打開頁面時提示這個錯誤:php

Fatal error: Call to undefined function: file_put_contents()函數

  意思是請求未定義的函數,出現這個提示一般有兩種狀況:spa

  1.當前php版本不支持此函數.net

  2.請求的函數是用戶自定義編寫,可是找不到這個函數所在的文件code

  file_put_contents函數的php支持版本是從5.0開始,見:http://cn2.php.net/manual/zh/function.file-put-contents.phpblog

  查看了一下機器當前php版本是4.4.2,那麼就出現第一種狀況php版本不支持了,不過就算版本不支持仍是能夠作下改動讓它支持的:get

  

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函數以前的代碼文件中就能夠解決問題,從新打開頁面就不會出現這個提示。it

相關文章
相關標籤/搜索