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