Request to answer

Source: Internet
Author: User
Tags tmp file
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;
}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.