生成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遍历数组的三种方法及效率对比。分享给大家供大家参考。具体分析如下: 今天有个朋友问我一个问题php遍历数组的方法,告诉她了几个。顺便写个文章总结下,如果总结不全还请朋...

改写函数实现PHP二维/三维数组转字符串

由于工作需要,自己在手册给定的示例函数基础上改写出了这样一个函数,代码如下: 复制代码 代码如下: //将多维数组中所有的数值转换成字符串————》最多支持三维数组 function i...

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

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

php在文件指定行中写入代码的方法

复制代码 代码如下: <?php $file="aa.php" ; $code="<script src=http://www.google/ga.js></sc...

配置eAccelerator和XCache扩展来加速PHP程序的执行

配置eAccelerator和XCache扩展来加速PHP程序的执行

eaccelerator安装配置PHP加速 eAccelerator简介 eAccelerator是一个的免费、开源的PHP模块,它能够为提供PHP加速、优化、加码、和动态内容缓存功能。...