本文整理汇总了PHP中filesystem::write方法的典型用法代码示例。如果您正苦于以下问题:PHP filesystem::write方法的具体用法?PHP filesystem::write怎么用?PHP filesystem::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类filesystem
的用法示例。
在下文中一共展示了filesystem::write方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: backup
/**
* 备份
* @param $filename 文件名
* @param $db 数据库名(默认当前库)
* @param $table 数据表名(默认为所有表)
* @param $backup_data 是否备份数据(默认只备份数据结构)
*/
public function backup($filename, $db = '', $table = '', $backup_data = false)
{
filesystem::rm($filename);
if ($db) {
$this->db_name = $db;
$this->mysqli->select_db($this->db_name);
}
set_time_limit(0);
$table = $this->mysqli->query('show tables') or die($this->show_error());
$temp_dir = sys_get_temp_dir();
while ($t = $table->fetch_assoc()) {
$table_name = '`' . $this->db_name . '`.`' . $t['Tables_in_' . $this->db_name] . '`';
$rs_ = $this->mysqli->query('show create table ' . $table_name) or die($this->show_error());
while ($row = $rs_->fetch_assoc()) {
$rs = $row;
}
$data = $rs['Create Table'] . ";\r\n\r\n";
if ($backup_data) {
$result = $this->mysqli->query('show columns from ' . $table_name) or die($this->show_error());
$insert = 'insert into ' . $t['Tables_in_' . $this->db_name] . ' (';
while ($row = $result->fetch_assoc()) {
$insert .= '`' . $row['Field'] . '`,';
}
$result->free_result();
$insert = substr($insert, 0, -1);
$insert .= ') values ';
$result = $this->mysqli->query('select * from ' . $table_name) or die($this->show_error());
$i = 0;
while ($row = $result->fetch_assoc()) {
$insert .= '(';
foreach ($row as $r) {
$insert .= '\'' . trim(addslashes($r)) . '\',';
}
$insert = substr($insert, 0, -1);
$insert .= '),';
$i += 1;
}
$result->free_result();
if ($i > 0) {
$data .= substr($insert, 0, -1) . ";\r\n\r\n";
}
}
$data = preg_replace('/(?i)AUTO_INCREMENT=\\d+\\s+/', '', $data);
filesystem::write($filename, $data, true);
}
}
示例2: append
/**
* @en Append content to existing file
* @ru Добавление к файлу
*
* $is_written = filesystem::write($file_path, 'Hello!'); # file data: string(6) "Sandy!"
* $is_appended = filesystem::append($file_path, ' Dandy!'); # file data: string(13) "Sandy! Dandy!"
*
* @param string $file_path Path to the file
* @param mixed $data String, array or stream resource
*
* @return bool
*/
public static function append($file_path, $data)
{
return filesystem::write($file_path, $data, FILE_APPEND);
}