生成ubuntu自动切换壁纸xml文件的php代码
2015-01-24信息快讯网
运行代码后在图片目录下会生成yuxing.xml,方便ubuntu自动切换壁纸.
<?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';
?>
如何使用Linux的Crontab定时执行PHP脚本的方法
php中使用DOM类读取XML文件的实现代码
php中XMLHttpRequest(Ajax)不能设置自定义的Referer的解决方法
DISCUZ在win2003环境下 Unable to access ./include/common.inc.php in... 的问题终极解决方案
php数组函数序列之array_intersect() 返回两个或多个数组的交集数组
php数组函数序列之array_unshift() 在数组开头插入一个或多个元素
php数组函数序列之array_unique() - 去除数组中重复的元素值
php数组函数序列 之array_count_values() 统计数组中所有值出现的次数函数
让Json更懂中文(JSON_UNESCAPED_UNICODE)
Array of country list in PHP with Zend Framework
php XMLWriter类的简单示例代码(RSS输出)
PHP用SAX解析XML的实现代码与问题分析
PHP-CGI进程CPU 100% 与 file_get_contents 函数的关系分析
PHP中将数组转成XML格式的实现代码
PHP源代码数组统计count分析
使用GROUP BY的时候如何统计记录条数 COUNT(*) DISTINCT
mysql_num_rows VS COUNT 效率问题分析
PHP无敌近乎加密方式!
PHP实现多条件查询实例代码
PHP中开发XML应用程序之基础篇 添加节点 删除节点 查询节点 查询节
php set_magic_quotes_runtime() 函数过时解决方法
PHP print类函数使用总结
PHP XML操作的各种方法解析(比较详细)
PHP操作xml代码
PHP XML error parsing SOAP payload on line 1
PHP中json_encode、json_decode与serialize、unserialize的性能测试分析
IIS下PHP连接数据库提示mysql undefined function mysql_connect()
PHP XML数据解析代码
php UTF-8、Unicode和BOM问题
php file_get_contents函数轻松采集html数据
Fatal error: Call to undefined function curl_init()解决方法
php echo()和print()、require()和include()函数区别说明
Search File Contents PHP 搜索目录文本内容的代码
PHP has encountered an Access Violation 错误的解决方法
PHP has encountered an Access Violation at 7C94BD02解决方法