生成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中在PDO中使用事务(Transaction)

并且在执行的过程中, 如果其中的某条执行失败, 可以回滚所有已更改的操作. 如果执行成功, 那么这一系列操作都会永久有效. 事务很好的解决了在操作数据库的时候不同步的问题. 同时, 通过...

解析php入库和出库

数据放入数据库和取出来显示在页面需要注意什么 入库时 $str=addslashes($str); $sql=\"insert into `tab` (`content`) values...

深入解析PHP 5.3.x 的strtotime() 时区设定 警告信息修复

PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *...

php数组使用规则分析

本文实例分析了php中数组的使用规则。分享给大家供大家参考。具体分析如下: 数组在php中处于灰常重要的地位。字符串、图片、数码、视频等值都以数组的形式存在,所以了解清楚数组的各种规则十...

php使用for语句输出三角形的方法

本文实例讲述了php使用for语句输出三角形的方法。分享给大家供大家参考。具体实现方法如下: <?php //phpinfo(); function Dis($n...