9 * write out a file to disk
11 * @param string $filename
12 * @param string $contents
13 * @param boolean $create_dirs
16 function smarty_core_write_file($params, &$smarty)
18 $_dirname = dirname($params['filename']);
20 if ($params['create_dirs']) {
21 $_params = array('dir' => $_dirname);
22 require_once(SMARTY_DIR
. 'core' . DIRECTORY_SEPARATOR
. 'core.create_dir_structure.php');
23 smarty_core_create_dir_structure($_params, $smarty);
26 // write to tmp file, then rename it to avoid
27 // file locking race condition
28 $_tmp_file = $_dirname . DIRECTORY_SEPARATOR
. uniqid('');
30 touch($_tmp_file); // php bug
31 if (!($fd = @fopen
($_tmp_file, 'w'))) {
32 $smarty->trigger_error("problem writing temporary file '$_tmp_file'");
36 fwrite($fd, $params['contents']);
37 if (isset($params['timestamp'])) {
38 touch($_tmp_file, $params['timestamp']);
41 if(file_exists($params['filename'])) {
42 @unlink
($params['filename']);
44 @rename
($_tmp_file, $params['filename']);
45 @chmod
($params['filename'], $smarty->_file_perms
);
50 /* vim: set expandtab: */