生成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';
?>

相关文章

json的键名为数字时的调用方式(示例代码)

对于键名为数字或者非正常变量字符时(如有空格),必须使用obj[xx]方式获取值。复制代码 代码如下:<?php //声明json数据$array = array('result'...

PHP多线程编程之管道通信实例分析

本文实例讲述了PHP多线程编程之管道通信用法。分享给大家供大家参考。具体分析如下: 一个线程如果是个人英雄主义,那么多线程就是集体主义,你不再是一个独行侠,而是一个指挥家。 管道通信:...

php变量与JS变量实现不通过跳转直接交互的方法

本文实例讲述了php变量与JS变量实现不通过跳转直接交互的方法。分享给大家供大家参考,具体如下: 大家都知道如果JS变量要获取后台传来的php变量可以这么写: <?ph...

PHP转换IP地址到真实地址的方法详解

想要把IPv4地址转为真实的地址,肯定要参考IP数据库,商业的IP数据库存储在关系型数据库中,查询和使用都非常方便,但是成本不是个人和小公 司愿意承受的,所以简单应用的思路就是利用一些免...

PHP的几个常用加密函数

MD5加密: string md5 ( string $str [, bool $raw_output = false ] ) 1.md5()默认情况下以 32 字符十六进制数字形式返回...