changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / libs / core / core.write_file.php
1 <?php\r
2 /**\r
3  * Smarty plugin\r
4  * @package Smarty\r
5  * @subpackage plugins\r
6  */\r
7 \r
8 /**\r
9  * write out a file to disk\r
10  *\r
11  * @param string $filename\r
12  * @param string $contents\r
13  * @param boolean $create_dirs\r
14  * @return boolean\r
15  */\r
16 function smarty_core_write_file($params, &$smarty)\r
17 {\r
18     $_dirname = dirname($params['filename']);\r
19 \r
20     if ($params['create_dirs']) {\r
21         $_params = array('dir' => $_dirname);\r
22         require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.create_dir_structure.php');\r
23         smarty_core_create_dir_structure($_params, $smarty);\r
24     }\r
25 \r
26     // write to tmp file, then rename it to avoid\r
27     // file locking race condition\r
28     $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('');\r
29 \r
30     if (!($fd = @fopen($_tmp_file, 'w'))) {\r
31         $smarty->trigger_error("problem writing temporary file '$_tmp_file'");\r
32         return false;\r
33     }\r
34 \r
35     fwrite($fd, $params['contents']);\r
36     fclose($fd);\r
37     if(file_exists($params['filename'])) {\r
38         @unlink($params['filename']);\r
39     }\r
40     @rename($_tmp_file, $params['filename']);\r
41     @chmod($params['filename'], $smarty->_file_perms);\r
42 \r
43     return true;\r
44 }\r
45 \r
46 /* vim: set expandtab: */\r
47 \r
48 ?>\r