Uploading an audio recording to mysql and playing in website

后端 未结 8 1519
生来不讨喜
生来不讨喜 2020-12-03 09:44

I have an upload phone app that uploads either images or audio recordings. The image can be uploaded to a mysql database and displayed no problem in a webpage, The problem i

8条回答
  •  一向
    一向 (楼主)
    2020-12-03 09:51

    Yes.

    // Get the file contents from the database...
    
    // Assuming a DB wrapper here.
    $results = $db->query('SELECT `file_contents` FROM `mp3s` WHERE `id` = :id', array(':id' => $_GET['id'])->execute();
    $fileContents = $results[0]['file_contents'];
    
    // Send appropriate headers for content type and force download
    header('Content-Type: mpeg/audio');
    header('Content-Disposition: attachment; filename="BullsOnPowerade.mp3"')
    echo $fileContents;
    

提交回复
热议问题