php文件生成模块<?php <br />
<br>
/*<br>
* 描 述 : 把数据写入文件<br>
*/<br>
namespace Model\Backend;<br>
class FilePutModel<br>
{<br>
/* 关闭自动连接数据库 */<br>
protected $autoCheckFields = false;<br>
<br>
private $m_DirName; //目录地址<br>
private $m_FileName; //文件名称<br>
private $m_Suffis; //文件后缀名<br>
private $m_DataArray; //需要写入文件的数据<br>
<br>
/*<br>
* 构造方法<br>
*/<br>
public function __construct($DirName, $FileName, $DataArray, $Suffis = null)<br>
{<br>
$this->m_DirName = null;<br>
$this->m_FileName = null;<br>
$this->m_FileSuffix = null;<br>
$this->m_DataArray = array();<br>
<br>
/* 基础数据设置 */<br>
$this->m_DirName = $DirName;<br>
$this->m_FileName = $FileName;<br>
$this->m_FileSuffix = $Suffis;<br>
$this->m_DataArray = $DataArray;<br>
<br>
/* 基础数据处理 */<br>
$this->IsDirThere();<br>
$this->IsFileSuffix();<br>
}<br>
<br>
/*<br>
* 数据处理<br>
*/<br>
public function SetFileData()<br>
{<br>
if(false == empty($this->m_FileName) && false == empty($this->m_DataArray)) {<br>
$Statu = file_put_contents(PATH_PHP_FILE.$this->m_FileName.'.'.$this->m_FileSuffix, "<?php \n\rreturn ".var_export($this->m_DataArray, true).";\n\r?>");<br>
if(false != $Statu) {<br>
return true;<br>
} else {<br>
return false;<br>
}<br>
} else {<br>
return '数据不能为空!';<br>
}<br>
}<br>
<br>
/*<br>
* 判断目录是否存在<br>
*/<br>
private function IsDirThere()<br>
{<br>
if(false == is_dir($this->m_DirName)) {<br>
mkdir($this->m_DirName, 0777, true);<br>
}<br>
}<br>
<br>
/*<br>
* 判断后缀名是否存在<br>
*/<br>
private function IsFileSuffix()<br>
{<br>
if(true == empty($this->m_FileSuffix)) {<br>
$this->m_FileSuffix = 'php';<br>
}<br>
}<br>
}<br>
?><br>
//使用说明<br>
$FilePutObj = new \Model\Backend\FilePutModel('路径',文件名称,'数据','文件后缀名');<br>
if(true == $FilePutObj->SetFileData()) {<br>
//成功<br>
}
http://www.schoolcms.cn 魔鬼发布
AD:真正免费,域名+虚机+企业邮箱=0元