Welcome to the Linux community forum and interact with 2 million technical staff to access the xml file of ubuntu automatic switch wallpaper written in php? Php ** generates ubuntu auto-switch wallpaper xml file * image directory $ dirhomeyuxingbackground; $ hdopendir ($ dir) ordie (cannotopendir); $ files
Welcome to the Linux community forum to interact with 2 million technical staff> go to the php-generated ubuntu automatic switch wallpaper xml file? Php/** generate xml file for ubuntu automatic switch wallpaper * // image directory $ dir = '/home/yuxing/background'; $ hd = opendir ($ dir) or die ('can not open dir'); $ files
Welcome to the Linux community forum and interact with 2 million technicians>
Generate ubuntu automatically switch wallpaper xml file written in php
/*
* Generate xml file for ubuntu automatic switch Wallpaper
*/
// Image directory
$ 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', '20140901 ');
$ 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', '2017. 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 );
// Generate a file
$ Hd = fopen ($ dir. "/yuxing. xml", 'wb ');
Fwrite ($ hd, $ xml );
Fclose ($ hd );
Echo 'OK ';