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

yipeiwu_com6年前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基于curl post实现发送url及相关中文乱码问题解决方法

本文实例讲述了PHP基于curl post实现发送url及相关中文乱码问题解决方法。分享给大家供大家参考,具体如下: 这个问题困扰我几天了,发送的指定网址的url参数,中文总是乱码,指定...

php-perl哈希算法实现(times33哈希算法)

复制代码 代码如下:APR_DECLARE_NONSTD(unsigned int) apr_hashfunc_default(const char *char_key, &n...

php四种定界符详解

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

php cookie使用方法学习笔记分享

PHP setcookie() 函数向客户端发送一个 HTTP cookie。cookie 是由服务器发送到浏览器的变量。cookie 通常是服务器嵌入到用户计算机中的小文本文件。每当计...

php中全局变量global的使用演示代码

我来给处入行的人讲解一下全局变量global的使用,”全局变量“,这个名词中的全局两个字已经告诉我们这个变量在各个地方都能用,先看一个实例: 复制代码 代码如下: <?php $a...