လက်ရှိတည်နေရာ: ပင်မစာမျက်နှာ> နောက်ဆုံးရဆောင်းပါးများစာရင်း> PHP သင်ခန်းစာ: Base64 encoded string ကိုပုံသို့မည်သို့ပြောင်းလဲရန်နှင့်သိမ်းဆည်းရမည်နည်း

PHP သင်ခန်းစာ: Base64 encoded string ကိုပုံသို့မည်သို့ပြောင်းလဲရန်နှင့်သိမ်းဆည်းရမည်နည်း

gitbox 2025-07-01

base64 encoding ဆိုတာဘာလဲ။

Base64 encoding သည် binary data ကို ASCII ဇာတ်ကောင်များအဖြစ်ပြောင်းလဲရန်အသုံးပြုသောနည်းလမ်းဖြစ်သည်။ ၎င်းသည် binary data တိုင်းကို 6-bit set တိုင်းနှင့်၎င်းကိုပုံနှိပ်နိုင်သောစာလုံးများအဖြစ်သို့ပြောင်းလဲသည်။ ဤ encoding method သည် Encode image image, audio or video or daties များအဖြစ် base64 strings များအဖြစ် binary data ထဲတွင် binary data in ကိုထုတ်လွှင့်ရန်နှင့်သိမ်းဆည်းရန်အသုံးပြုသည်။

PHP ကို ​​အသုံးပြု. Base64 encoded string ကိုပြောင်းရန်

PHP တွင် base64_decode () function ကို function သည် base64 encoded string ကို binary data ထဲသို့ decode လုပ်ရန်အသုံးပြုနိုင်သည်။ Base64 encoded string ကိုရုပ်ပုံတစ်ခုသို့ပြောင်းလဲရန်နမူနာကုဒ်ဖြစ်သည်။

 
$base64String = "iVBORw0KG…"; // Base64encoded ကြိုး
$imageData = base64_decode($base64String); // decodingBase64ကြိုး
file_put_contents("image.png", $imageData); // 保存decoding后的图片

ဖော်ပြချက်

အထက်ဖော်ပြပါကုဒ်များတွင် base64_decode () ကို အသုံးပြု. binary data များသို့ decoded သော base64string သည် based64 encoded image data တစ်ခုဖြစ်ပြီး၎င်းကို file_put_contents () function ကိုဖြတ်ပြီး ပုံတစ်ပုံ အဖြစ်သတ်မှတ်သည်။

Dynamicy ပုံရိပ်ဖိုင်အမည်ကိုသတ်မှတ်ပါ

ပုံ၏အမည်အနေဖြင့်ဖိုင်အမည်ကို dvonically သတ်မှတ်ရန်လိုအပ်ပါကအထက်ဖော်ပြပါကုဒ်များကိုပြုပြင်ပြီးအောက်ပါနည်းလမ်းကိုသုံးနိုင်သည်။

 
$base64String = "iVBORw0KG…"; // Base64encoded ကြိုး
$imageData = base64_decode($base64String); // decodingBase64ကြိုး
$filename = 'image_' . time() . '.png'; // dynamically ပုံရိပ်ဖိုင်အမည်များကိုထုတ်ပေးသည်
file_put_contents($filename, $imageData); // 保存decoding后的图片

ဖော်ပြချက်

ဤကုဒ်တွင်ဖိုင်အမျိုးအစားကိုလက်ရှိ timestamp ကိုဖွင့ ်. 0 ယ်ယူသော image file name တစ်ခုစီသည်ထူးခြားပြီးဖိုင်အမျိုးအစားပ conflicts ိပက်ခများကိုရှောင်ရှားရန်သေချာသည်။

အကျဉ်းချုပ်

Base64_Decode () function and function_put_contents () function ကိုအသုံးပြုခြင်း () function ကို အသုံးပြု. Base64 encoded strings များကိုကျွန်ုပ်တို့အလွယ်တကူ ပြောင်းလဲ. ဒေသအလိုက်သိမ်းဆည်းနိုင်သည်။ ဖိုင်အမည်ကိုမှန်ကန်စွာချမှတ်ခြင်းအားဖြင့်ဖိုင်အမည်ပ conflicts ိပက်ခများကိုလည်းရှောင်ရှားနိုင်သည်။ ဤနည်းလမ်းသည်ကွန်ယက်ဒေတာလွှဲပြောင်းခြင်းသို့မဟုတ်ဖိုင်သိုလှောင်မှုတွင်အလွန်အသုံးဝင်သည်။

ယခုသင်ခန်းစာသည် PHP တွင် Base64 encoded ကြိုးများကိုမည်သို့ကိုင်တွယ်ရမည်ကိုပိုမိုနားလည်ရန်မျှော်လင့်ပါသည်။