How to register a midi data URI on the server (coldfusion or php)

advertisements

I have a dataURI that when used as the href of link tag saves beautifully as a midi file when clicked on in Chrome, and after save plays fine (see code)... my question is if I sent that string to the server how can I save it as a file that plays? I tried urldecoding and base64 encoding, but the file saved cannot play... if you could provide code in php or coldfusion that saves the string to a plauyable file that would be great!

    <a href="data:audio/midi,MThd%00%00%00%06%00%01%00%02%01%e0MTrk%00%00%00%1a%00%C0%02%00%FF%51%03%05%16%15%00%FF%03%08%43%6f%6f%6c%65%79%27%73%00%FF%2F%00MTrk%00%00%06%5e%00%C0%02%00%90%3e%40%83%51%3e%00%0f%40%40%81%61%40%00%0f%47%40%81%43%47%00%0f%48%40%1e%48%00%00%47%40%81%43%47%00%0f%45%40%81%61%45%00%0f%47%40%83%51%47%00%0f%40%40%81%61%40%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%45%40%81%61%45%00%0f%47%40%81%61%47%00%0f%4a%40%81%61%4a%00%0f%47%40%81%61%47%00%0f%45%40%81%61%45%00%0f%43%40%81%61%43%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%45%40%81%61%45%00%0f%3e%40%81%61%3e%00%0f%47%40%81%61%47%00%0f%3e%40%81%61%3e%00%0f%45%40%81%61%45%00%0f%3e%40%81%61%3e%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%45%40%81%61%45%00%0f%3e%40%81%61%3e%00%0f%4a%40%81%61%4a%00%0f%45%40%81%61%45%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%81%61%40%00%0f%47%40%81%61%47%00%0f%47%40%81%61%47%00%0f%45%40%81%61%45%00%0f%47%40%83%51%47%00%0f%40%40%81%61%40%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%45%40%81%61%45%00%0f%47%40%81%61%47%00%0f%4a%40%81%61%4a%00%0f%4c%40%81%61%4c%00%0f%4e%40%81%61%4e%00%0f%4f%40%81%61%4f%00%0f%51%40%81%61%51%00%0f%4e%40%81%61%4e%00%0f%4c%40%81%61%4c%00%0f%49%40%81%61%49%00%0f%4a%40%81%61%4a%00%0f%47%40%81%61%47%00%0f%45%40%81%61%45%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%81%61%40%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%83%51%40%00%0f%3e%40%83%51%3e%00%0f%40%40%81%61%40%00%0f%47%40%81%43%47%00%0f%48%40%1e%48%00%00%47%40%81%43%47%00%0f%45%40%81%61%45%00%0f%47%40%83%51%47%00%0f%40%40%81%61%40%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%45%40%81%61%45%00%0f%47%40%81%61%47%00%0f%4a%40%81%61%4a%00%0f%47%40%81%61%47%00%0f%45%40%81%61%45%00%0f%43%40%81%61%43%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%45%40%81%61%45%00%0f%3e%40%81%61%3e%00%0f%47%40%81%61%47%00%0f%3e%40%81%61%3e%00%0f%45%40%81%61%45%00%0f%3e%40%81%61%3e%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%45%40%81%61%45%00%0f%3e%40%81%61%3e%00%0f%4a%40%81%61%4a%00%0f%45%40%81%61%45%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%81%61%40%00%0f%47%40%81%61%47%00%0f%47%40%81%61%47%00%0f%45%40%81%61%45%00%0f%47%40%83%51%47%00%0f%40%40%81%61%40%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%45%40%81%61%45%00%0f%47%40%81%61%47%00%0f%4a%40%81%61%4a%00%0f%4c%40%81%61%4c%00%0f%4e%40%81%61%4e%00%0f%4f%40%81%61%4f%00%0f%51%40%81%61%51%00%0f%4e%40%81%61%4e%00%0f%4c%40%81%61%4c%00%0f%49%40%81%61%49%00%0f%4a%40%81%61%4a%00%0f%47%40%81%61%47%00%0f%45%40%81%61%45%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%81%61%40%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%83%51%40%00%0f%4f%40%81%61%4f%00%0f%4e%40%81%61%4e%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%4c%40%81%61%4c%00%0f%4e%40%81%61%4e%00%0f%4f%40%81%61%4f%00%0f%4c%40%81%61%4c%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%4f%40%81%61%4f%00%0f%4c%40%81%61%4c%00%0f%4a%40%81%61%4a%00%0f%47%40%81%61%47%00%0f%45%40%83%51%45%00%0f%42%40%81%61%42%00%0f%45%40%81%61%45%00%0f%3e%40%81%61%3e%00%0f%45%40%81%61%45%00%0f%42%40%81%61%42%00%0f%45%40%81%61%45%00%0f%45%40%83%51%45%00%0f%42%40%81%61%42%00%0f%45%40%81%61%45%00%0f%4a%40%81%61%4a%00%0f%4c%40%81%61%4c%00%0f%4e%40%81%61%4e%00%0f%4f%40%81%61%4f%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%4f%40%81%61%4f%00%0f%47%40%81%61%47%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%4a%40%81%61%4a%00%0f%4c%40%81%61%4c%00%0f%4e%40%81%61%4e%00%0f%4f%40%81%61%4f%00%0f%51%40%81%61%51%00%0f%4e%40%81%61%4e%00%0f%4c%40%81%61%4c%00%0f%49%40%81%61%49%00%0f%4a%40%81%61%4a%00%0f%47%40%81%61%47%00%0f%45%40%81%61%45%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%81%61%40%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%83%51%40%00%0f%4f%40%81%61%4f%00%0f%4e%40%81%61%4e%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%4c%40%81%61%4c%00%0f%4e%40%81%61%4e%00%0f%4f%40%81%61%4f%00%0f%4c%40%81%61%4c%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%4f%40%81%61%4f%00%0f%4c%40%81%61%4c%00%0f%4a%40%81%61%4a%00%0f%47%40%81%61%47%00%0f%45%40%83%51%45%00%0f%42%40%81%61%42%00%0f%45%40%81%61%45%00%0f%3e%40%81%61%3e%00%0f%45%40%81%61%45%00%0f%42%40%81%61%42%00%0f%45%40%81%61%45%00%0f%45%40%83%51%45%00%0f%42%40%81%61%42%00%0f%45%40%81%61%45%00%0f%4a%40%81%61%4a%00%0f%4c%40%81%61%4c%00%0f%4e%40%81%61%4e%00%0f%4f%40%81%61%4f%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%4f%40%81%61%4f%00%0f%47%40%81%61%47%00%0f%4c%40%81%61%4c%00%0f%47%40%81%61%47%00%0f%47%40%83%51%47%00%0f%4a%40%81%61%4a%00%0f%4c%40%81%61%4c%00%0f%4e%40%81%61%4e%00%0f%4f%40%81%61%4f%00%0f%51%40%81%61%51%00%0f%4e%40%81%61%4e%00%0f%4c%40%81%61%4c%00%0f%49%40%81%61%49%00%0f%4a%40%81%61%4a%00%0f%47%40%81%61%47%00%0f%45%40%81%61%45%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%81%61%40%00%0f%42%40%81%61%42%00%0f%3e%40%81%61%3e%00%0f%40%40%83%51%40%00%00%FF%2F%00">Download Midi File</a>


Assuming $b64_href is your string. This code works for images.

if ($b64_href > 2) // to avoid substr error
{
    // DELETE "data:audio/midi," from your string
    $b64_sub = substr($b64_href, strpos($b64_href, ",") + 1);
    // CLEANUP replace space by plus
    $b64_clean = str_replace(' ', '+', $b64_sub);
    // DECODE your string
    $raw = base64_decode($b64_clean, true);
    if ($raw != FLASE)
        // SAVE
    else
        // HANDLE ERROR
}