1

I am developing an android app that download songs(so type of data is blob) from db.

I have the following download image code example:

<?php

    if($_SERVER['REQUEST_METHOD']=='GET'){
        $id = $_GET['id'];
        $sql = "select * from images where id = '$id'";
        require_once('dbConnect.php');

        $r = mysqli_query($con,$sql);

        $result = mysqli_fetch_array($r);

        header('content-type: image/jpeg');

        echo base64_decode($result['image']);

        mysqli_close($con);

    }else{
        echo "Error";
    }

How do I change "header" and "echo"(under header) to download an mp3 audio file ?

Mauricio Gracia Gutierrez
  • 10,288
  • 6
  • 68
  • 99
ZEUS
  • 37
  • 5
  • U said download songs but in your `header` have `('content-type: image/jpeg');` image format is it right ? – Karthi Oct 14 '16 at 12:45
  • 3
    Searching for "mime type music" gives http://stackoverflow.com/q/10688588/1741542 – Olaf Dietsche Oct 14 '16 at 12:48
  • yes, image/jpeg is for image...so i need for songs... – ZEUS Oct 14 '16 at 12:52
  • so change the mime type as per recommend by Mr. Olaf Dietsche – Karthi Oct 14 '16 at 12:53
  • yes...but the type of data into db to store song is long blob? – ZEUS Oct 14 '16 at 12:56
  • Blob is just the storage type for binary files in MySQL, you can put any binary data there - images, audio files, zip files etc. The script needs to know what kind of data the database contains and send a corresponding header. – Janek Oct 14 '16 at 13:00
  • yes, but when i choose file/in m way song) into db and after i click on save, not appear me "query successful"...why? – ZEUS Oct 14 '16 at 13:04

1 Answers1

1

You'll want to send the following header for a .mp3 file:

Content-Type: audio/mpeg3

Refer to https://www.sitepoint.com/web-foundations/mime-types-complete-list/ for a good list of MIME types.

Janek
  • 2,942
  • 1
  • 14
  • 14