首页 > 后端开发 > php教程 > 请求来解答

请求来解答

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-13 10:09:48
原创
948 人浏览过

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

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 !== '.' && !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');        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->_file_perms);        umask($old_umask);        return true;    } } 
登录后复制


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

------解决方案--------------------
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;




相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
No input file specified.这个咋解决
来自于 1970-01-01 08:00:00
0
0
0
No input file specified.打开页面就这样
来自于 1970-01-01 08:00:00
0
0
0
thinkphp中Controller里面使用Request::File('image');
来自于 1970-01-01 08:00:00
0
0
0
javascript - ie8下 jquery input file 无值
来自于 1970-01-01 08:00:00
0
0
0
javascript - <include file="Public:header"/>无效
来自于 1970-01-01 08:00:00
0
0
0
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板