2012-11-17 70 views
0

我正在使用Salesforce元數據API。我正在創建一個base64數據,其中包含一個項目清單,一個名爲package.xml的文件。如何從這些數據中獲取package.xml文件。如何從PHP中的Base64Binary編碼數據獲取原始數據?

請參考下面的編碼數據:

UEsDBBQACAAIAOcycUEAAAAAAAAAAAAAAAAhAAAAdW5wYWNrYWdlZC9vYmplY3RzL0NvbnRhY3Qub2JqZWN01Vffb9owEH7nr4jyPpxO0zRNIRWlVKDxS5CNR2SSC/FwHGo7tPnv65CAE0CoUFYxnnKfz+fvvrtLjH3/GlFjDVyQmDXMu7plGsC82Cds0TB/u09ffpj3Ts1uJULG0XD+FzxpqC1MNMxQytVPhESMV3URxNyDuhdH6KtlfUfWNxSBxD6W2HRqhvrZwPCcwhOALxzJE7BRGcl9AgJ0a+RAQukAR+D0MFskeAFiNvNstIO1J7xK4AzTru8EmIosvEa0G8VzoDqajXKg5ABsIUPnzrLUWv6sFzk8J4TD7oidrV0kx94yy6lDlGQ83boe4KUt6QocV9FVXtmjXkkYeU5gG6KwcqlQWatTwgH2J3GiqnNUthXxllQx0lAF/oNpAqK6WI0/hfmxwDtHHwKcULnNYWtWj0OnzjuDzCiMGRhdllUlvSFamEsG3BhDAJxjekPMVGOEWIBv9JT/7fAayhD4v6YjYi71LBdW7XDz/qiOCrw8rmfM4xrodV5iWaTDF9iHJ3oCXsx8fEsD5AKX5KYYjTiJPoHQJS164QfoHV29oUng5WhjNyltxUxiT4qjvR0Qqlp54sUqeFvdOFIZqktGdoLG91tcxTR00FKnK6PK5TS3B8Jl6ONUuCERfRUwvALFHN2v2EYwpzUcuM2WW3/ojt3OY9NtF0ruOauAHEt19XLURUKVyUYaqXqus+5w3E53Muur2B0b5UipFw74FCLukjey7I0i/cvF7KfvrnOfMDhd4X56lQIP4KWHhZwCLD+psq1xW5X1cXa94vaaE3c2bbd/nVFblbeRJW7kmX9IwKw7/msBN9NxgYCbsTgtoI3K/4Cc2htQSwcIRtMK5HUCAAA4DQAAUEsDBBQACAAIAOcycUEAAAAAAAAAAAAAAAAWAAAAdW5wYWNrYWdlZC9wYWNrYWdlLnhtbE2OzQrCMBCE732KkLvZWKSIpOmh4FUP+gBpumrVJKVZRd/e2h90TzPDx+yo4uXu7IldbILP+VJIztDbUDf+nPPjYbtY80Inam/szZyR9bSPOb8QtRuAGEwr4il0FoUNDlIpM5ArcEimNmS4Tlh/it4txlEP3qGr+pe6DJ6MJQVz8EO8cajLR6TgdtUVv9AQjYXw16im9TrNhFQwu0TBNFonH1BLBwj45N4QogAAAOYAAABQSwECFAAUAAgACADnMnFBRtMK5HUCAAA4DQAAIQAAAAAAAAAAAAAAAAAAAAAAdW5wYWNrYWdlZC9vYmplY3RzL0NvbnRhY3Qub2JqZWN0UEsBAhQAFAAIAAgA5zJxQfjk3hCiAAAA5gAAABYAAAAAAAAAAAAAAAAAxAIAAHVucGFja2FnZWQvcGFja2FnZS54bWxQSwUGAAAAAAIAAgCTAAAAqgMAAAAA 

我使用BASE64_DECODE()方法,但我得到的輸出象下面這樣:

PKç2qA!unpackaged/objects/Contact.objectÕWßoÚ0~篈ò>œNÓ4M!¥T ñKGd’ñpj;´ùïë€@¨PV1žrŸÏçï¾»KŒ}ÿQc \˜5Ì»ºeÀ¼Ø'lÑ0»O_~˜÷NÍn%BÆÑpþ–Øtj†úÙÀðœÂ€/É°QÉ}tkä@BéGàô0[$xb6ól´ƒµ'¼JàӮ,¼F´Ås :šr äl!CçβÔZþ¬9<'„Ã]$ÇÞ2Ë©C」d<ݺà¥-é WÑU^Ù£^IyN`¢°r©PY«SÂö'q¢ªsT¶ñ–T1ÒPþƒi¢ºX?…ù±À;GœP¹ÍakVC§Î;ƒÌ(Œ]–U%½!Z˜KÜCœczCÌTc„X€oô」ÿíðÊø¿¦#b.õ,Vípóþ¨Ž ¼<®gÌãèu^bY¤Ã؇'z^Ì||Kä—ä¦8‰>Ð%-záè]½¡Iàåhc7)mÅLbOŠ£½ªZyâÅ*x[Ý8RªKFv‚Æ÷[\Å4tÐR§+£Êå4·ÂeèãT¸!}0¼ÅݯØF0§5¸Í–[èŽÝÎcÓmJî9«€KuõrÔEB•ÉF©z®³îpÜNw2ë«ØåH©ø"î’7²ì"ýËÅì§ï®sŸ08]á~z•à¥‡…œ,?©²­q[•õqv½âöšw6m·Q[•·‘%nä™HÀ¬;þk7Óq€›±8- Êÿ€œÚPKFÓ äu8 PKç2qAunpackaged/package.xmlMŽÍ Â0„ï}Š»ÙX¤ˆ¤é¡àUúiºjÕ$¥YEßÞÚtO3ÃÇì¨âåîì‰]l‚ÏùRHÎÐÛP7þœóãa»XóB'joìÍœ‘õ´9¿µ€L+â)t… R)3+pH¦6d¸NXŠÞ-ÆQÞ¡«ú—ºžŒ%sðC¼q¨ËG¤àvÕ¿Ð…ðר¦õ:Í„T0»DÁ4Z'PKøäÞ¢æPKç2qAFÓ äu8 !unpackaged/objects/Contact.objectPKç2qAøäÞ¢æÄunpackaged/package.xmlPK「ª 
+1

這看起來像一個zip文件可能。 – Musa

+0

我想你會得到正確的解碼字符串。它看起來像一個壓縮或加密的文件。 –

回答

2

我試過這段代碼:

<?php 
header('Content-Type: application/zip'); 
header('Content-disposition: filename="my.zip"'); 
$s = "UEsDBBQACAAIAOcycUEAAAAAAAAAAAAAAAAhAAAAdW5wYWNrYWdlZC9vYmplY3RzL0NvbnRhY3Qub2JqZWN01Vffb9owEH7nr4jyPpxO0zRNIRWlVKDxS5CNR2SSC/FwHGo7tPnv65CAE0CoUFYxnnKfz+fvvrtLjH3/GlFjDVyQmDXMu7plGsC82Cds0TB/u09ffpj3Ts1uJULG0XD+FzxpqC1MNMxQytVPhESMV3URxNyDuhdH6KtlfUfWNxSBxD6W2HRqhvrZwPCcwhOALxzJE7BRGcl9AgJ0a+RAQukAR+D0MFskeAFiNvNstIO1J7xK4AzTru8EmIosvEa0G8VzoDqajXKg5ABsIUPnzrLUWv6sFzk8J4TD7oidrV0kx94yy6lDlGQ83boe4KUt6QocV9FVXtmjXkkYeU5gG6KwcqlQWatTwgH2J3GiqnNUthXxllQx0lAF/oNpAqK6WI0/hfmxwDtHHwKcULnNYWtWj0OnzjuDzCiMGRhdllUlvSFamEsG3BhDAJxjekPMVGOEWIBv9JT/7fAayhD4v6YjYi71LBdW7XDz/qiOCrw8rmfM4xrodV5iWaTDF9iHJ3oCXsx8fEsD5AKX5KYYjTiJPoHQJS164QfoHV29oUng5WhjNyltxUxiT4qjvR0Qqlp54sUqeFvdOFIZqktGdoLG91tcxTR00FKnK6PK5TS3B8Jl6ONUuCERfRUwvALFHN2v2EYwpzUcuM2WW3/ojt3OY9NtF0ruOauAHEt19XLURUKVyUYaqXqus+5w3E53Muur2B0b5UipFw74FCLukjey7I0i/cvF7KfvrnOfMDhd4X56lQIP4KWHhZwCLD+psq1xW5X1cXa94vaaE3c2bbd/nVFblbeRJW7kmX9IwKw7/msBN9NxgYCbsTgtoI3K/4Cc2htQSwcIRtMK5HUCAAA4DQAAUEsDBBQACAAIAOcycUEAAAAAAAAAAAAAAAAWAAAAdW5wYWNrYWdlZC9wYWNrYWdlLnhtbE2OzQrCMBCE732KkLvZWKSIpOmh4FUP+gBpumrVJKVZRd/e2h90TzPDx+yo4uXu7IldbILP+VJIztDbUDf+nPPjYbtY80Inam/szZyR9bSPOb8QtRuAGEwr4il0FoUNDlIpM5ArcEimNmS4Tlh/it4txlEP3qGr+pe6DJ6MJQVz8EO8cajLR6TgdtUVv9AQjYXw16im9TrNhFQwu0TBNFonH1BLBwj45N4QogAAAOYAAABQSwECFAAUAAgACADnMnFBRtMK5HUCAAA4DQAAIQAAAAAAAAAAAAAAAAAAAAAAdW5wYWNrYWdlZC9vYmplY3RzL0NvbnRhY3Qub2JqZWN0UEsBAhQAFAAIAAgA5zJxQfjk3hCiAAAA5gAAABYAAAAAAAAAAAAAAAAAxAIAAHVucGFja2FnZWQvcGFja2FnZS54bWxQSwUGAAAAAAIAAgCTAAAAqgMAAAAA"; 
$out = base64_decode($s); 
print($out); 
?> 

然後瀏覽器下載一個包含.xml文件的工作ZIP文件。

如果你想處理使用的PHP ZIP文件的內容,您可以啓用php_zip延伸,並檢查了這樣的回答:Unzip a file with php

+0

謝謝。我嘗試了相同的代碼,但它正在下載php文件本身,而不是一個zip文件 – user1808669

+0

我正在使用Xampp localhost。該文件名的擴展名爲.php,即WinRAR ZIP壓縮文件(1.1 kB)。下載完成後,雙擊它,它會在editot中打開一些特殊的charectors loke PK [] [] [] – user1808669

+0

下載該文件,將其重命名爲.zip並用解壓縮軟件打開它(或Windows內置的東西)。你也可以添加這個PHP代碼來強制文件名:'header('Content-disposition:filename =「my.zip」');' –

相關問題