File put contents

Wednesday, March 17th, 2010

file_put_contents() is in php nowadays, but if you’re on an old server you may need your own.
This simply checks if the function’s there, and if not it makes the function.

  1. // Replacement for file_put_contents if it doesn't exist
  2. if(!function_exists('file_put_contents')){
  3.         function file_put_contents($file, $data){
  4.                 $fp = fopen($file, 'w');
  5.                 fwrite($fp, $data);
  6.                 fclose($fp);
  7.         }
  8. }

Display clean php code for copying

// Replacement for file_put_contents if it doesn't exist
if(!function_exists('file_put_contents')){
	function file_put_contents($file, $data){
		$fp = fopen($file, 'w');
		fwrite($fp, $data);
		fclose($fp);
	}
}
click here to close

Help keep these files free,
and support further development!