Posted By

davemaven on 03/24/11


Tagged


Versions (?)

Extract photos from Windows Contacts


 / Published in: PHP
 

  1. <?php
  2. $file = $_SERVER['argv'][1];
  3. $xml = new SimpleXmlElement(file_get_contents($file));
  4. $xml->registerXPathNamespace('c', 'http://schemas.microsoft.com/Contact');
  5. $nodes = $xml->xpath('//c:contact/c:PhotoCollection/c:Photo/c:Value');
  6. if (empty($nodes)) {
  7. echo "No photos found\n";
  8. }
  9.  
  10. foreach ($nodes as $i => $photo) {
  11. $out = basename($file,'.contact').'-'.($i+1).'.jpg';
  12. if (file_put_contents($out, base64_decode($photo)) === false) {
  13. echo "Error writing to $out\n";
  14. } else {
  15. echo "Wrote $out\n";
  16. }
  17. }

Report this snippet  

You need to login to post a comment.