生成ubuntu自动切换壁纸xml文件的php代码

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

<?php
/*
* 生成ubuntu自动切换壁纸xml文件
*/
//图片目录
$dir = '/home/yuxing/background';

$hd = opendir($dir) or die('can not open dir');
$files = array();
while($file = readdir($hd)) {
$tem = "$dir/$file";
if (is_file($tem) && in_array(strtolower(substr(strrchr($file,'.'), 1)), array('jpg', 'gif')))
$files[] = $tem;
}
closedir($hd);
unset($file);

$xw = new xmlWriter();
$xw->openMemory();
$xw->setIndent(true);
$xw->setIndentString(' ');
$xw->startDocument('1.0', 'utf-8');
$xw->startElement('background');
$xw->startElement('starttime');
$xw->writeElement('year', '2000');
$xw->writeElement('month', '01');
$xw->writeElement('day', '01');
$xw->writeElement('hour', '00');
$xw->writeElement('minute', '00');
$xw->writeElement('second', '00');
$xw->endElement();
$count = count($files);
for ($i=0; $i<$count; $i++) {
$xw->startElement('static');
//$xw->writeElement('duration', '1795.0');
$xw->writeElement('duration', '30.0');
$xw->writeElement('file', $files[$i]);
$xw->endElement();
$xw->startElement('transition');
$xw->writeElement('duration', '5');
$xw->writeElement('from', $files[$i]);
$xw->writeElement('to', isset($files[$i+1]) ? $files[$i+1] : $files[0]);
$xw->endElement();
}
$xw->endElement();
$xml = $xw->outputMemory(true);
//生成文件
$hd = fopen($dir . "/yuxing.xml", 'wb');
fwrite($hd, $xml);
fclose($hd);
echo 'ok';
?>

相关文章

几款免费开源的不用数据库的php的cms

1、MuCMS一个小型,平台独立的内容管理系统适用于非交互式网站(网站只发布信息)。它对系统要求非常低,只需要Apache+PHP。没有使用数据库。它具有安全,快速,易用等特点。官方网站...

PHP 编程请选择正确的文本编辑软件

如果您在修改任何PHP文件后发生:     不能登入或者不能登出;     页顶出现一条空白;  ...

高级php注入方法集锦第1/2页

'%23  ' and passWord='mypass  id=-1 union select 1,1,1&nbs...

PHP中一些可以替代正则表达式函数的字符串操作函数

0x01:根据预定义的字符对字符串进行词法分析 复制代码 代码如下: <?php /*  * 在处理大量信息时,正则表达式函数会使速度大幅减慢。应当在需要使用正则...

php简单获取文件扩展名的方法

本文实例讲述了php简单获取文件扩展名的方法。分享给大家供大家参考。具体实现方法如下: <?php function get_file_extension($file...