if (!function_exists(file_put_contents)) {
// Define constants used by function, if not defined
if (!defined(FILE_USE_INCLUDE_PATH)) define(FILE_USE_INCLUDE_PATH, 1);
if (!defined(FILE_APPEND)) define(FILE_APPEND, 8);
// Define function and arguments
function file_put_contents($file, &$data, $flags=0)
{
// Varify arguments are correct types
if (!is_string($file)) return(false);
if (!is_string($data) && !is_array($data)) return(false);
if (!is_int($flags)) return(false);
// Set the include path and mode for fopen
$include = false;
$mode = wb;
// If data in array type..
if (is_array($data)) {
// Make sure its not multi-dimensional
reset($data);
while (list(, $value) = each($data)) {
if (is_array($value)) return(false);
}
unset($value);
reset($data);
// Join the contents
$data = implode(, $data);
}
// Check for flags..
// If include path flag givin, set include path
if ($flags&FILE_USE_INCLUDE_PATH) $include = true;
// If append flag givin, set append mode
if ($flags&FILE_APPEND) $mode = ab;
// Open the file with givin options
if (!$handle = @fopen($file, $mode, $include)) return(false);
// Write data to file
if (($bytes = fwrite($handle, $data)) === false) return(false);
// Close file
fclose($handle);
// Return number of bytes written
return($bytes);
}
}
или вот так коротко
function file_put_contents($file,$data)
{
$cf=@fopen($file,"a+");
@fwrite($cf,$data);
@fclose($cf);
return;
}
|