PHP字节数组到Base64(来自Mssql的字节数组)

时间:2016-11-06 18:54:02

标签: php arrays sql-server base64

我在表上使用Mssql和图像,如“0xFFD8FFE000104A46494 ....”。我认为它是字节数组

我想用PHP将其改为图像。

我试试这个;

<?php $resim="0xFFD8FFE000104A46494...."; ?>

<img src="data:image/jpeg;base64,<?php echo base64_encode($resim);?>" />

但图片没有显示。

代码演示:(http://sandbox.onlinephpfunctions.com/code/61b8f073a70100338681e8ab37b0a75c930eca6e

2 个答案:

答案 0 :(得分:1)

您需要将十六进制字符串从SQL Server转换为base64。试试这个,它应该工作:

<?php

$resim="0xFFD8FFE000104A46494600010100000100010000FFDB008400090607131212151313121515121615121817181215161615151518151716171815171A1D2920181A251B171522312125292B2E2E2E171F3338332F37282D2E2B010A0A0A0E0D0E1A10101A2D251D252D2D2D2D2D2D2D2D2D2D2D2D2D2B2D2B2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2D2B2D2D2D2D2D2D2D2D2D2D2D2DFFC0001108010300C303012200021101031101FFC4001C0001000203010101000000000000000000000607030405020108FFC4004710000103010405080606080603010000000100020311040512210631415191071322326171A1C142528192B1D114235372A2B2151633626382B3E124437383D2F093A3C234FFC4001801010101010100000000000000000000000001020304FFC4001F1101000300020203010000000000000000000102111331122103224151FFDA000C03010002110311003F00BC51110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110163B4485AD7380C44349037902B45911044A5D2F734D0C2D69DCE7D1C076846E998FB36FFE41F25A5A6718169068338DBE05C170DED69A1A0AD770DC57A2B4ACC74F3CDED139A980D2C14EA37DFF00ECBE1D2E1F663DFF00ECA32D6B72E88E0164C0CF55BC02DF155392C92374B07D97E31F25E86950FB2FC7FD946B9A67AADE0178104632C0DE0138AABC964A8E9381FE51F7BFB2F5FACC3EC8FBC3E4A282CCC3E88E0BEB6C91D7AADE0A7154E4B254349DBF667DE1F25F3F5A19F667885183668FD56F058FE8F10D6D054E3AA72592E6E9333D477108ED2660F41DC42889822DC38958248195D5C09F9ACF1C2F24A65FAD51FD9BFF000FCD7DFD6A8FECE4E0DF9AAB0B25C7293CE86E2A4785B952833AE127AD5CF3CB88D8649203106BA5CDDF5B888C3830389A518D23A41BB769F64F0AB7B6FEC2C1934E606B8B4C72E5B833757D65919A6F663AC483BDA3C8AACD86BACD7BF5A93681C38AD409F458F3F01E6B8CBB62CA057D44441111011110111101111042B4F9B47C477B5C38107CD44ADB210CA83438E2151B8C8D0470254DB4FA3AB623B8BC7100F9284DA5F8585C6BD1CF2CF219EA3AF52F4FC73F579EF1F674218EA359E35F8ACA60FDE77E1F30B59AF3889D47B3FEEB5E997CC3A8BC545467AC778DEBA30D9309D8E77E0FF8AF2587D63E1F25E5979447548383BE4BEB676BB36BC13D88BED82691C1EC6870A3B156A33146D452842CAD6BC9EB0F74FF00C96B4FFB48BEF3FF002396FC0E1B683B4945C78FA33CFA63DC3FF24758DDEBB781F9ADF639A46B07B882BD960DCA4B3AE77D15DFBBE2B14D038027A39039548F22BA525762E64C49AF71D6694C9458F6F90CB58DA7555AD34EF155EAD2EA31C7F75DF05AB64943D80005B840147536346796CCF6AF76A3F54EFBBFD949E9623DB8D1A9972751FD748EDD1D38B87C94398A77C9C33F6C7FD31F9BE41795EA4D511110444404444044440444411CD396FD430EE9078B5DF20ABEBC5B58641FB8FF00CA558FA66DAD949DCE8CFE203CD57B21A8237823885DBE39F4E57ED9A220D08EC3E6A057CB29689731FB47EDDE6BE6A69774B58A33B4C6C3F842AEF4AADEE8EDB386E1231372731AE19C6C76D1DABA30F7806F1C54B7429D46BF3A8AF9055E3AFB275C511F63DBF91E0298E815BB1C721C0D690F03A25E6BD11EBB8D3D898A95DA1FD38BEFBBFA4F59ED34C27B8AE5DAA6E9C79FA67FA522CD24B5073D855104FD3126D7F1FEEBDB2FE78FF300F60AFC170C35A402F7BC76358C70F1942CAC821D93D3EFC4F1F9712B38CECA7DA27793E573AAE2680766BAEEEE5D7BE9D4865DFCDC9F94EA517D076B47385B207E6C19078A64EF59A37ECAA90DECFAC4F1BDB4E3979ACB4E8B401403214D8B0DE4FF00AB23BBE21791266B56F07F447691F027C94B7457B6AC6AC4E4ED9F5323B7BE9C1A3E6ABA8959DA02CA596BBDEF3F01E4BCCF44A468888822220222202222022220E469636B649BB1A1DEEB83BC9557F4A56E5FF1E2B34E37C32F1C068A9373976F8FA73BF6D8BBED3489829A9B4E19792806998FF19213E908CE5FE9B479299585FD1FE693F3B945B4CE40CB4F51AF0E8E3347E3A6D1E839A766F5D18465C7B7C14DB93D77425CFD26FE551516B848CECC076C533DA7FF0067383C14A342258C89446D9066C279C7B5F5AE2A50863771D886251680498CFF0011DFD2916569D7DC7E0B189246E2780D7B18D3D17B4D2AEA375822A75F5AB95464BC3662E0E269521D5A642B4DDB1264C566C81D4AF36683224B5C003B454517C046EE15F9AD8B2DDEF7805AE8C9A6A1231AE1DF8885B4CBAAD19D181D4D6237B247767458E25048F4069CDCA7F883C180F9A905E4EE87F34438C8D1E6B89A190C8C8DC246398E321347B5CD34C2D1501D9D35E7DEBAB6F3901FC487C2469F241D16396ADE0EC877F911E6B2B5CB5ADFE8FB7C966DD2D7B798D5B1A1ACA58E2EDC678BDCAA8895C1A38CC365847F0D8788AF9AF3BBCBA28888822220222202222022220C768662639BBDAE1C4515084E455FEA87B64186491BB9EF1C1C42E9F1B17869588F5BEF3BC68EF351ED398EB2C6EDF0B3C1CF52586CEE697920805C2876751A3C96B5F773CF308A4862320635CD75301CC3AA06171A9D67505D19C57AE6760F657E7452AD0239CD953F65AFFDC5E2D1649195E72C05BFCB686EAEDC587C16CE8B4B197CA1B1BA375184D5F88645D4A0C208DBAC9431DAB75B9CC2181F46BF0870F5BA6C0DF1355EAC2EEB0272A3BE0B1DAA369730968243B224548E89D5BB62CD0C7D6A7AAEF82A2BD8ECDACB4B4D3592E0DF68C54C97A15068DCC9DA083C287577AEE0B8718C8D053538B012453536A32ED5EE6D17701AB1034CA30EC8D3D605DDF9FF00653CA09A4BABA10C221756A4F38EA620465863D87DABB16AD71EF3237C013E4B5346AC4608CB08A1A93435AE74D750372DCB59E9C3FEABBFA5214D5C6DAE45F3316C9101B49AF76417683547AFC77F888B701F127E4A4F4476E947A95D5608F0C51B773183834054BD9D952D1BC81C55DE02E0EB2FA88888222202222022220222202A634860A5A671FC694F1713E6AE7553E974445B2714F49A78B1A7CD6E9DB36462B57B8655A34E5ACD6BAF82D8DB5F1DAB23D8756745E0403665DC29F05D596616978D4F77BC579B45B1EFA07BB150EE15DDAE9DAB1987B4FB0FCEABCBA23BFC2BE688D5B43685BF7BC8ADCB26107A64E1D470531508CE95CAAB03D95A6AC8D73AD7E0BD069DDF0F80CD51BF0E8FD88D4B2DD688C9FB6879C2370AB0D281651A2B5EA5E165908EAF3C1D081DA72352B4227D35E5DE29F15B0D941EDEE59986A25B4FB0BA1385C637655062787B08EC7507C1684E6B245D8E79E11B879ADA6B97C368A3E36E74A4A723B3A39712908DAA8A64A377FB6B265EA8F32A42D1E2A3D7B7ED5DD987E0B36587734047D22D9131C326073DDDB830D3F115742A87926A1B73E9ADB67713D98A4606FC1DC15BCB9CB622228088880888808888088880AB6BFAF37B6D536598752ADA36AD1D5C5910ECB7AB2555FA6B039B6A91D84869C041A1A1E836B43DEB749F6CDA3D35C5F11D487B58E71A7598DA8D7EAD37EE599AFB23B5C607DD7B9BE0E14508173BCC98DD255A1D5E8F59D9D6872F33A9771A575D86312165D5667F5647B7D8D78FC256393469BE85A187EF82CF8AE1E10B232678D4F771344D8325BD368C4E336B5AF1BD8E69F35AAFBA6666B8DD4FBA7E2B41FA4B85F8490483424B4501AD2988536E5AD486C1A43233676D03DC333DF554F6E2F37EC3DCBC3A1075D09DE402A58DD2563BF69103F798C70F22BDFD26C4FD71B01ECC71FCC286A2221FFA091F02BE363E98754920380AD28012DAECEC0A5C6E8B33FA8E78FBAE63C7C6AB4A5B91A1FD19361EBB1CD1E8EDA514C5D7289C9472D9532B8015248000D64D000029ACF74B83490E638015AB5C0E5BD71F44C59FF48074F3451B584BDA257B59CE48080C0DC445483D2CBD559B35575B92ABBF9ABCAF361353132C5193FBC58E73E9D9881F0569AAFF0092F7892D37BCC330EB7BD808A50888610411AC50AB01729684444044440444404444044440512E55E1C5755A7B044EF76563BE00A96AE0E9EC38EEDB60DBF469C8EF6B0B87C158ED27A707932BBE0B4DD5667CB0B1CEC32B0B8B4633CDCD2479BB5FA3BD752DFA1F630D73C9742D682E73849D16802A49C75002E1F23F784715CE1F2BC3238A5B4E2738D001CE17FF00F438AE34F68B4E914C638B1417544F18DFA9F3386741BDDD9A9B913534035EF653F1AD71B0DE169923B1B1CEB2C7506D12F41B8A9934340CC9A8CB58199A5403D0BCF452D5031D23B9A31B01739C240D0D68152497E1A00159176DDF058E06C5135B1411B4D05680019B9CE71D67592E26A73255597C5BE6D21B57D12CAE74776C4419E5029CE1D6DA03B72E8B767588D403C8C45AC772B6D05D6889B248CC799634BA312644E234AE2191A139557662791AFDAAE5BA2EB8ACB0B208181914628D68E2493AC926A49399249555E91DEB2DF77836EFB13CB2CB67762B4DA63D64B4D0863B756AD68F48D4E6D6D55F3D3C5AAD982CA40560C9A1365200689194A66247389EFC78940666092F4FD1D64ACA1809B44AFA0105358C874C8AB4532E93A9B0D11631C6D20BC9D106E1DB8AAED605057777F05B5A3B7C4B2461D8DEDCDC050BA840CABC54B6DBA07291918A41B9D51E0411E2A35359CC768365A7F886B41314747B836808346D72A50F710B5E498F77D5EB2981CD73AA0D0755B5D62B434AAEC5AB432C367BB1D68B7599B2CCC89F21C45CD7073BA910208A6785BDE4A8FDB639498D91B073DCFD9F0B65AB417738D23165D5CB82EE72A76B96D0EB0DD7D1135A6563E61112E6B6369A03570048EBBF57F92B166A1B3C81D9705DCF3EBDA653C191B7C3091EC564AD0B96E786C91086CECC1182E752AE7749C4B9C6AE24E6495BEB32A22228088880888808888088880B52F6871C12B3D68A46F1691E6B6D0841F96B472D8D91B1D9AD7687C5610F74AE6C4DC4E7BC868228DCF3A531674CE833AABFEE0D27BB39B64366B440C63400C8C9111037063E87C37A847249A3D0C8CB6C369B347288E7681CF46D750E12D2062191A35A72F5948EF3E49AED96B8192407F812380F71F89BE0BA5A62659AEE233A4D7E4F7DDA7F4758096D91A6B689FD17341A13DACCBA2DF4CE7D51556768F5C70D8A0659E06E163769EB3DC7ACF79F49C76955B4DC91DA6025D61BC9F19DCEC7113BB13E170AFB5A56191BA4F640685B696D0E6DE665232D62A23793C752931BD4ABA1CAB697CAE7B6E9B012EB64E4364730E71B1C2B841F45C5B993E8B6A768225FA09A2715D9656C0CE93CF4A59299C925333D8D1A80D806FA934CE845FCDBA26966B7D8AD2EB44AE3F5D202D786935700250D05CE7549762CF2DD9D9F61E562EB91B5333E320569244FDD5A07341693DC549892259B951D31176D9096106D5355903759AFA5253686D47792D1B579E4AB444DDF65C52E76B9C8927738D5C09CDB193B69524EF739CA11A083F4D5EB25E369734450380B340E73490466CE8D6BD1EB13B5EE14D54576293E8737492F98EC56696D32F522617535173B53583B5CE200EF502E456E891ED9EF4B4E768B63DD849D9162A92DAE6039C321EAC6CA2E5F2A76B75E778D9AE685C4303DB25A1CDD9954FBB1D4E79173DA362B76C7666451B238DA1B1B1AD635A3535AD14007700115536971C7A51606FAB1444ECD5F497F902B3F278FFD257C5B6F239C30FD459CECA757137F91A5DFEF9510E57AF57437CCB23327C7666B01F54C90BDB8876812D7BD5B3C955C3F42BB608CB70C8F1CEC9BF1C94343DA1B81BFCAACF48972222CA88888088880888808888088880888831C70B5A496B5A0B8D5D400623BCD35959111011110797B011420107583982A3D79E825DD3D4C9638B11F4A36F34FF7A3A1F152344157DEBC89D8E4CE19A689DB316199A3DE18BF12E6FEA05F764FFF001DE58DA3535D248C1EC8E4E719E215C48B5E5298FCF572D9EF8BA6D335ADF77BA6926C5CE3DCD329E93F1BCB5F038E1C4684D5BE88D4A5377F2E3162C169B1CB1B81A1E69ED908DF563C31C3BA855B8B52F0BB209C619A18E56EE958D78FC41363F4C7E7E9628EFABFC98F11B3CAF85C71B4B4F350C31738083AAA585BFCCBF460552727F77471DFF780898D645146E6B1AC146B6A61A803666D72B6D2C40888B2A22220222202222022220222202222022220222202222022220222208F5C9A2ACB35B2D56B12171B491569680199D4E75CEA7B9485110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111101111011110111107FFFD9";  

// Remove 0x from the string start
$resim = substr($resim, 2);

// Convert hexadecimal string to binary
$bin = hex2bin($resim);

// Convert binary to base64
$base64_image = base64_encode($bin);
?>

<img src="data:image/jpeg;base64,<?php echo $base64_image;?>" />

答案 1 :(得分:0)

您需要致电base64_decode()