Php code for generating ubuntu auto-switch wallpaper xml file _ PHP Tutorial

Source: Internet
Author: User
Generate php code for the ubuntu automatic switch wallpaper xml file. Copy the code as follows :? Php ** generates ubuntu auto-switch wallpaper xml file * image directory $ dirhomeyuxingbackground; $ hdopendir ($ dir) ordie (cannotopendir); $ fi The code is as follows:


/*
* 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 ';
?>

The http://www.bkjia.com/PHPjc/322262.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322262.htmlTechArticle code is as follows :? Php/** generate xml file for ubuntu automatic switch Wallpaper * // image directory $ dir = '/home/yuxing/background'; $ hd = opendir ($ dir) or die ('Can not open dir'); $ fi...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.