Last active
December 14, 2015 07:48
-
-
Save rixrix/5052850 to your computer and use it in GitHub Desktop.
A simple script that will extract image(s) from MS Access DB exported as XML file. It uses XMLReader basically to extrac big XML files. Tested on 1.11GB file size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env php | |
| <?php | |
| /** | |
| * Here's a little script that will extract images from MS Access DB exported as XML file. | |
| * It uses XMLReader basically to extract big XML files. Tested on 1.11GB file size | |
| */ | |
| function xmlparser($file, $saveTo = '') { | |
| $wrapperName = 'Photo'; | |
| $xml = new XMLReader(); | |
| if (!$xml->open($file)) die('Unable to read file!!! \n'); | |
| while($xml->read()) { | |
| if($xml->nodeType==XMLReader::ELEMENT && $xml->name == $wrapperName){ | |
| $filename = ''; | |
| $filedata = ''; | |
| while($xml->read() && $xml->name != $wrapperName){ | |
| if($xml->nodeType==XMLReader::ELEMENT){ | |
| if ($xml->name == 'FileName') { | |
| $xml->read(); | |
| $filename = $xml->value; | |
| } | |
| if ($xml->name == 'FileData') { | |
| $xml->read(); | |
| $filedata = $xml->value; | |
| } | |
| } | |
| } | |
| if (!empty($filedata)) { | |
| $fp = fopen($saveTo . "/{$filename}", "wb+"); | |
| fwrite($fp, substr(base64_decode($filedata), 20)); // @see http://stackoverflow.com/a/6163979/2117526 | |
| fclose($fp); | |
| echo "Saving {$filename}... \n"; | |
| } | |
| } | |
| } | |
| $xml->close(); | |
| echo "Done!"; | |
| } | |
| xmlparser('/path/to/xml/file', '/path/to/save/direcotory'); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment