PHP file generation module

Source: Internet
Author: User
Provides various official and user-released code samples for reference. You are welcome to learn more about the PHP file generation module.

/*
* Description: write data to a file.
*/
Namespace Model \ Backend;
Class FilePutModel
{
/* Disable automatic database connection */
Protected $ autoCheckFields = false;

Private $ m_DirName; // directory address
Private $ m_FileName; // file name
Private $ m_Suffis; // file suffix
Private $ m_DataArray; // data of the file to be written

/*
* Constructor
*/
Public function _ construct ($ DirName, $ FileName, $ DataArray, $ Suffis = null)
{
$ This-> m_DirName = null;
$ This-> m_FileName = null;
$ This-> m_FileSuffix = null;
$ This-> m_DataArray = array ();

/* Basic Data settings */
$ This-> m_DirName = $ DirName;
$ This-> m_FileName = $ FileName;
$ This-> m_FileSuffix = $ Suffis;
$ This-> m_DataArray = $ DataArray;

/* Basic Data Processing */
$ This-> IsDirThere ();
$ This-> IsFileSuffix ();
}

/*
* Data Processing
*/
Public function SetFileData ()
{
If (false = empty ($ this-> m_FileName) & false = empty ($ this-> m_DataArray )){
$ Statu = file_put_contents (PATH_PHP_FILE. $ this-> m_FileName. '.'. $ this-> m_FileSuffix ," M_DataArray, true). "; \ n \ r?> ");
If (false! = $ Statu ){
Return true;
} Else {
Return false;
}
} Else {
Return 'data cannot be blank! ';
}
}

/*
* Determine whether a directory exists
*/
Private function IsDirThere ()
{
If (false = is_dir ($ this-> m_DirName )){
Mkdir ($ this-> m_DirName, 0777, true );
}
}

/*
* Determine whether the suffix exists
*/
Private function IsFileSuffix ()
{
If (true = empty ($ this-> m_FileSuffix )){
$ This-> m_FileSuffix = 'php ';
}
}
}
?>
// Instructions for use
$ FilePutObj = new \ Model \ Backend \ FilePutModel ('path', file name, 'data', 'file extension name ');
If (true = $ FilePutObj-> SetFileData ()){
// Succeeded
}
Http://www.schoolcms.cn devil release

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.