请求来解答
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了请求来解答,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2581字,纯文字阅读大概需要4分钟。
内容图文
![请求来解答](/upload/InfoBanner/zyjiaocheng/210/645c4c6fbb004269a8728802a4b19645.jpg)
- PHP code
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;
}
}
内容总结
以上是互联网集市为您收集整理的请求来解答全部内容,希望文章能够帮你解决请求来解答所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】