• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/internals/core.write_file.php

00001 <?php
00016 function smarty_core_write_file($params, &$smarty)
00017 {
00018     $_dirname = dirname($params['filename']);
00019 
00020     if ($params['create_dirs']) {
00021         $_params = array('dir' => $_dirname);
00022         require_once(SMARTY_CORE_DIR . 'core.create_dir_structure.php');
00023         smarty_core_create_dir_structure($_params, $smarty);
00024     }
00025 
00026     // write to tmp file, then rename it to avoid
00027     // file locking race condition
00028     $_tmp_file = tempnam($_dirname, 'wrt');
00029 
00030     if (!($fd = @fopen($_tmp_file, 'wb'))) {
00031         $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
00032         if (!($fd = @fopen($_tmp_file, 'wb'))) {
00033             $smarty->trigger_error("problem writing temporary file '$_tmp_file'");
00034             return false;
00035         }
00036     }
00037 
00038     fwrite($fd, $params['contents']);
00039     fclose($fd);
00040 
00041     // Delete the file if it allready exists (this is needed on Win,
00042     // because it cannot overwrite files with rename()
00043     if (file_exists($params['filename'])) {
00044         @unlink($params['filename']);
00045     }
00046     @rename($_tmp_file, $params['filename']);
00047     @chmod($params['filename'], $smarty->_file_perms);
00048 
00049     return true;
00050 }
00051 
00052 /* vim: set expandtab: */
00053 
00054 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2