1: <?php
2: 3: 4: 5: 6:
7:
8: 9: 10: 11: 12: 13: 14: 15:
16: function smarty_core_write_file($params, &$smarty)
17: {
18: $_dirname = dirname($params['filename']);
19:
20: if ($params['create_dirs']) {
21: $_params = array('dir' => $_dirname);
22: require_once(SMARTY_CORE_DIR . 'core.create_dir_structure.php');
23: smarty_core_create_dir_structure($_params, $smarty);
24: }
25:
26:
27: $_tmp_file = tempnam($_dirname, 'wrt');
28:
29: if (!($fd = @fopen($_tmp_file, 'wb'))) {
30: $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
31: if (!($fd = @fopen($_tmp_file, 'wb'))) {
32: $smarty->trigger_error("problem writing temporary file '$_tmp_file'");
33: return false;
34: }
35: }
36:
37: fwrite($fd, $params['contents']);
38: fclose($fd);
39:
40: if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
41:
42:
43:
44: @unlink($params['filename']);
45: @rename($_tmp_file, $params['filename']);
46: }
47: @chmod($params['filename'], $smarty->_file_perms);
48:
49: return true;
50: }
51:
52:
53:
54: ?>