Changeset 330 for trunk/lib/Utilities.inc.php
- Timestamp:
- May 6, 2008 9:21:27 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Utilities.inc.php
r320 r330 398 398 } 399 399 400 /* 401 * Writes content to the specified file. This function emulates the functionality of file_put_contents from PHP 5. 402 * 403 * @access public 404 * @param string $filename Path to file. 405 * @param string $content Data to write into file. 406 * @return bool Success or failure. 407 * @author Quinn Comendant <quinn@strangecode.com> 408 * @since 11 Apr 2006 22:48:30 409 */ 410 function filePutContents($filename, $content) 411 { 412 $app =& App::getInstance(); 413 414 // Open file for writing and truncate to zero length. 415 if ($fp = fopen($filename, 'w')) { 416 if (flock($fp, LOCK_EX)) { 417 if (!fwrite($fp, $content, mb_strlen($content))) { 418 $app->logMsg(sprintf('Failed writing to file: %s', $filename), LOG_ERR, __FILE__, __LINE__); 419 fclose($fp); 420 return false; 421 } 422 flock($fp, LOCK_UN); 423 } else { 424 $app->logMsg(sprintf('Could not lock file for writing: %s', $filename), LOG_ERR, __FILE__, __LINE__); 425 fclose($fp); 426 return false; 427 } 428 fclose($fp); 429 // Success! 430 $app->logMsg(sprintf('Wrote to file: %s', $filename), LOG_DEBUG, __FILE__, __LINE__); 431 return true; 432 } else { 433 $app->logMsg(sprintf('Could not open file for writing: %s', $filename), LOG_ERR, __FILE__, __LINE__); 434 return false; 435 } 436 } 437 438 400 439 /** 401 440 * If $var is net set or null, set it to $default. Otherwise leave it alone.
Note: See TracChangeset
for help on using the changeset viewer.