【问题标题】:Issue in php with "header"php中带有“标题”的问题
【发布时间】:2017-02-23 21:42:36
【问题描述】:

我正在开发一个从 db 下载歌曲(所以数据类型是 blob)的 android 应用程序。

我有以下下载图片代码示例:

<?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";
    }

如何更改“header”和“echo”(在 header 下)以下载 mp3 音频文件?

【问题讨论】:

  • 你说下载歌曲但在你的header('content-type: image/jpeg'); 图像格式对吗?
  • 搜索“mime type music”会得到stackoverflow.com/q/10688588/1741542
  • 是的,image/jpeg 用于图像...所以我需要歌曲...
  • 所以按照 Olaf Dietsche 先生的建议更改 mime 类型
  • 是的...但是存储歌曲的 db 中的数据类型是 long blob?

标签: php android


【解决方案1】:

您需要为 .mp3 文件发送以下标头:

Content-Type: audio/mpeg3

请参阅https://www.sitepoint.com/web-foundations/mime-types-complete-list/ 以获得 MIME 类型的良好列表。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 2011-12-21
    • 1970-01-01
    • 1970-01-01
    • 2011-04-01
    • 2013-04-04
    • 2014-01-03
    相关资源
    最近更新 更多