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
00027
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
00042
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
00053
00054 ?>