Copy CodeThe code is as follows:
/*
* Generate Ubuntu Auto Switch wallpaper XML file
*/
Picture Catalogue
$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);
Generating files
$HD = fopen ($dir. "/yuxing.xml", ' WB ');
Fwrite ($HD, $xml);
Fclose ($HD);
echo ' OK ';
?>
The above describes the PHP code generation ubuntu automatically switch wallpaper XML file PHP code, including the content of the PHP code, I hope to be interested in PHP tutorial friends helpful.