【示例7:把工程中的所有腳本全部保存為txt文件】
<?php
include_once('rxdata_library.php');
if (!is_writable(getcwd())) {
die('當前文件夾下無寫入權限!');
}
$folder_name = 'scripts';
if (is_dir($folder_name)) {
// 如果目錄存在,則刪除目錄下所有文件
$dir = opendir($folder_name);
while ($file = readdir($dir)) {
$file = $folder_name . '/' . $file;
if (!is_dir($file)) {
unlink($file);
}
}
closedir($dir);
} else {
mkdir($folder_name);
}
$scripts = rxdata_load('project/Data/Scripts.rxdata');
foreach ($scripts as $script) {
if ($script[1] == '')
$script[1] = 'empty';
$filename = $folder_name . '/' . $script[1] . '.txt';
$fp = fopen($filename, 'w');
fwrite($fp, gzuncompress($script[2]));
fclose($fp);
}
printf("共保存了%d個文件", count($scripts));
?>
【運行結果】
保存的txt文件:
打開其中一個txt文件查看: