Results 1 to 4 of 4

Thread: PHP writes XML of jpegs in folder

  1. #1
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP writes XML of jpegs in folder

    Hi,
    Im trying to write some PHP that writes an XML of jpegs in a folder BASED on the upload/modified date. I have a code that that does it in alpha-numeric order... can anyone help?

    PHP Code:
    <?
    $xml 
    '<?xml version="1.0"?'.'><images>';
    $handle opendir(".");
    $doc "gallery.xml";
    $handle2 fopen($doc'w') or die("can't open file");
    while ( (
    $file=readdir($handle)) !== false ) {
        if ( !
    is_dir($file) ){
            
    $pic = @getimagesize($file);
        
            if(
    $pic != false && $pic[2] == 2){
                
    $xml .= '<pic><image>/images/galleries/'.$file.'</image><width>'.$pic[0].'</width><height>'.$pic[1].'</height></pic>';
            }
        }
    }
    $xml .= "</images>";
    fwrite($handle2$xml);
    fclose($handle2);
    echo 
    $xml;
    ?>

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    PHP Code:
    <?php
    $doc 
    "gallery.xml";
    ///////////
    $xml '<?xml version="1.0"?><images>';
    foreach(
    glob('./*.jpg') as $file){
      
    $pic = @getimagesize($file);
      
    $xml .= '<pic><image>/images/galleries/'.substr($file2).'</image><width>'.$pic[0].'</width><height>'.$pic[1].'</height></pic>';
    }
    $xml .= "</images>";
    file_put_contents($doc$xml);
    echo 
    $xml;

  3. #3
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    does this code put the files in order of most recently added to the folder?

  4. #4
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    No, but this one does:
    PHP Code:
    <?php
    $doc 
    "gallery.xml";
    ///////////
    function sortMod($file1$file2){
      
    $file1 filectime($file1);
      
    $file2 filectime($file2);
      if(
    $file1 == $file2)
        return 
    0;
      return 
    $file1 $file2 ? -1:1;
    }
    $xml '<?xml version="1.0"?><images>';
    $list glob('./*.jpg');
    usort($list'sortMod');
    foreach(
    $list as $file){
      
    $pic = @getimagesize($file);
      
    $xml .= '<pic><image>/images/galleries/'.substr($file2).'</image><width>'.$pic[0].'</width><height>'.$pic[1].'</height></pic>';
    }
    $xml .= "</images>";
    file_put_contents($doc$xml);
    echo 
    $xml;

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •