Request experts to come in and answer questions, online and other PHPcodeclassSmarty_Internal_Write_File {/*** Writesfileinasavewaytodisk *** @ params
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; } }
What does this code mean, urgent, online, etc?
------ Solution --------------------
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) {// The Path (folder) does not exist
Mkdir ($ _ dirpath, $ smarty-> _ dir_perms, true); // Create
}
// Write to tmp file, then move to overt file lock race condition
$ _ Tmp_file = tempnam ($ _ dirpath, 'wrt '); // tempnam should be the directory for converting the conversion path to the configured template, it is the location where the smarty template file is converted into a php code file.
If (! ($ Fd = @ fopen ($ _ tmp_file, 'wb') {// check whether the directory can be operated
$ _ Tmp_file = $ _ dirpath. DS. uniqid ('wrt '); // convert the file name
If (! ($ Fd = @ fopen ($ _ tmp_file, 'wb '))){
Throw new SmartyException ("unable to write file {$ _ tmp_file }");
Return false;
}
}
Fwrite ($ fd, $ _ contents); // write the converted content to convert the smarty code to the php code,
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;
}
}