生成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调用新浪短链接API的方法

本文实例讲述了php调用新浪短链接API的方法。分享给大家供大家参考。具体方法如下: 复制代码 代码如下:<?php //Sina App_Key define('SINA...

php中session定期自动清理的方法

下文来为各位介绍PHP设置session定期自动清理的例子了,因为session默认是15分钟自动把变量给清除内存了,但有一些时间并不生效了,下面我们就来看看。 配置完成php后默认ph...

刚才在简化php的库,结果发现很多东西

php的ming库用来生成flash!虽然模块是试验性质的, 不过比较有趣。一张大大的表, 很有趣, 给人一种在8g的感觉。 sapi/php4activescript.dll (p...

PHP小技巧搜集,每个PHPer都来露一手

这个帖子主要是所有的PHPers把自己在开发或学习中的一些经验技巧进行总结,主要就是把解决某种事情更好的方法告诉大家. 我先说几个: 1,假如你使用echo输出一个简单的语句,类似与:...

php四种定界符详解

闲来无事,研究了与java、c#完全不同的领域php,php即(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”),对于学习php的初学者,不得...