Хранилища Subversion ant

Редакция

Содержимое файла | Последнее изменение | Открыть журнал | RSS

Редакция Автор № строки Строка
304 alex-w 1
<?php
2
 
3
/**
4
* Smarty write file plugin
5
*
6
* @package Smarty
7
* @subpackage PluginsInternal
8
* @author Monte Ohrt
9
*/
10
/**
11
* Smarty Internal Write File Class
12
*/
13
class Smarty_Internal_Write_File {
14
    /**
15
    * Writes file in a save way to disk
16
    *
17
    * @param string $_filepath complete filepath
18
    * @param string $_contents file content
19
    * @return boolean true
20
    */
21
    public function writeFile($_filepath, $_contents)
22
    {
23
        $_dirpath = dirname($_filepath);
24
        // if subdirs, create dir structure
25
        if ($_dirpath !== '.' && !file_exists($_dirpath)) {
26
            mkdir($_dirpath, 0755, true);
27
        }
28
        // write to tmp file, then move to overt file lock race condition
29
        $_tmp_file = tempnam($_dirpath, 'wrt');
30
 
31
        if (!file_put_contents($_tmp_file, $_contents)) {
32
            throw new Exception("unable to write file {$_tmp_file}");
33
            return false;
34
        }
35
        // remove original file
36
        if (file_exists($_filepath))
37
            unlink($_filepath);
38
        // rename tmp file
39
        rename($_tmp_file, $_filepath);
40
        // set file permissions
41
        chmod($_filepath, 0644);
42
 
43
        return true;
44
    }
45
}
46
 
47
?>