请求来解答

Jun 13, 2016 pm 01:48 PM
file filepath smarty tmp

请求高手进来解答,在线等

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->class Smarty_Internal_Write_File {
    /**
     * Writes file in a save way to disk
     * 
     * @param string $_filepath complete filepath
     * @param string $_contents file content
     * @return boolean true
     */
    public static function writeFile($_filepath, $_contents, $smarty)
    {
        $old_umask = umask(0);
        $_dirpath = dirname($_filepath); 
        // if subdirs, create dir structure
        if ($_dirpath !== '.' &amp;&amp; !file_exists($_dirpath)) {
            mkdir($_dirpath, $smarty-&gt;_dir_perms, true);
        } 
        // write to tmp file, then move to overt file lock race condition
        $_tmp_file = tempnam($_dirpath, 'wrt');

        if (!($fd = @fopen($_tmp_file, 'wb'))) {
            $_tmp_file = $_dirpath . DS . uniqid('wrt');
            if (!($fd = @fopen($_tmp_file, 'wb'))) {
            throw new SmartyException("unable to write file {$_tmp_file}");
            return false;
            }
            }

        fwrite($fd, $_contents);
        fclose($fd);

        // remove original file
        if (file_exists($_filepath))
            @unlink($_filepath); 
        // rename tmp file
        rename($_tmp_file, $_filepath); 
        // set file permissions
        chmod($_filepath, $smarty-&gt;_file_perms);
        umask($old_umask);
        return true;
    } 
} 

Copy after login


详细点翻译下这段代码是什么意思,紧急用,在线等

------解决方案--------------------
class Smarty_Internal_Write_File {
/**
* Writes file in a save way to disk

* @param string $_filepath complete filepath
* @param string $_contents file content
* @return boolean true
*/
public static function writeFile($_filepath, $_contents, $smarty)
{
$old_umask = umask(0);
$_dirpath = dirname($_filepath); //$_filepath的路径
// if subdirs, create dir structure
if ($_dirpath !== '.' && !file_exists($_dirpath)) {//路径(文件夹)不存在
mkdir($_dirpath, $smarty->_dir_perms, true);//创建

// write to tmp file, then move to overt file lock race condition
$_tmp_file = tempnam($_dirpath, 'wrt');//tempnam应该是转换路径到配置的模板转换保存目录,就是smarty模板文件转换成php代码文件的文件存放的位置

if (!($fd = @fopen($_tmp_file, 'wb'))) {//检查目录是否可以操作
$_tmp_file = $_dirpath . DS . uniqid('wrt');//转换文件名
if (!($fd = @fopen($_tmp_file, 'wb'))) {
throw new SmartyException("unable to write file {$_tmp_file}");
return false;
}
}

fwrite($fd, $_contents);//写转换后的内容,就是把smarty代码转换成php代码,
fclose($fd);

// remove original file
if (file_exists($_filepath))
@unlink($_filepath); 
// rename tmp file
rename($_tmp_file, $_filepath); 
// set file permissions
chmod($_filepath, $smarty->_file_perms);
umask($old_umask);
return true;




Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The cleaning principle of /tmp/ folder in Linux system and the role of tmp file The cleaning principle of /tmp/ folder in Linux system and the role of tmp file Dec 21, 2023 pm 05:36 PM

The cleaning principle of /tmp/ folder in Linux system and the role of tmp file

Hongmeng native application random poetry Hongmeng native application random poetry Feb 19, 2024 pm 01:36 PM

Hongmeng native application random poetry

Use java's File.length() function to get the size of the file Use java's File.length() function to get the size of the file Jul 24, 2023 am 08:36 AM

Use java's File.length() function to get the size of the file

How to convert php blob to file How to convert php blob to file Mar 16, 2023 am 10:47 AM

How to convert php blob to file

What does tmp mean in linux What does tmp mean in linux Mar 10, 2023 am 09:26 AM

What does tmp mean in linux

Rename files using java's File.renameTo() function Rename files using java's File.renameTo() function Jul 25, 2023 pm 03:45 PM

Rename files using java's File.renameTo() function

Use java's File.getParentFile() function to get the parent directory of the file Use java's File.getParentFile() function to get the parent directory of the file Jul 27, 2023 am 11:45 AM

Use java's File.getParentFile() function to get the parent directory of the file

How to access and clean junk files in /tmp directory in CentOS 7? How to access and clean junk files in /tmp directory in CentOS 7? Dec 27, 2023 pm 09:10 PM

How to access and clean junk files in /tmp directory in CentOS 7?

See all articles