07-21-2008, 11:15 PM
|
#2 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Without looking into fopen flags, here's what I would do off the top of my head:
PHP Code:
function file_put_contents($szFilename, $szInject) {
$szInput = file_get_contents($szFilename); $szOutput = fopen($szFilename, 'w+');
$szInput = $szInject."\n".$szInput;
$put = fwrite($szContent, $szInput);
return ($put == TRUE) ? TRUE : FALSE;
}
Now after looking into fopen flags...
'w+' won't work, because as the manual says: Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
Your function will probably work just the way it is if you change w+ to r+, like so:
PHP Code:
function file_put_contents($szFilename, $szInject) { // Open the file $szContent = fopen($szFilename, 'r+'); // Write the text into it $put = fwrite($szContent, $szInject); if($put) { // If success, return true return true; } // If failure, return false return false;
}
-m
|
|
|
|