生成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入门教程之数组用法汇总(创建,删除,遍历,排序等)

本文实例总结了PHP数组用法。分享给大家供大家参考,具体如下: Demo1.php <?php //创建一个数组变量 $userNames = array('张...

PHP异常类及异常处理操作实例详解

本文实例讲述了PHP异常类及异常处理操作。分享给大家供大家参考,具体如下: 异常处理归类于错误处理,PHP从5.1.0开始增加了Exception异常处理类。 一、异常处理 PHP 异常...

PHP设计模式之装饰者模式代码实例

定义: 装饰者模式就是不修改原类代码和继承的情况下动态扩展类的功能。传统的编程模式都是子类继承父类实现方法重载,使用装饰器模式,只需添加一个新的装饰器对象,更加灵活,避免类数量和层次过多...

PHP 时间日期操作实战

常见常用的时间函数: 1.time(); //取得1970/1/1 00:00:00 到现在的总秒数 <?echo time();?> 2.mktime(); //设定时间...

phpinfo的知识点总结

phpinfo是一个运行指令,为显示php服务器的配置信息。 phpinfo-输出大量PHP信息 bool phpinfo() 输出 PHP 当前状态的大量信息,包含了 PHP 编...