0

我正在开发一个小型网站,用户可以在其中下载 mp3 文件。用 PHP & Codeigniter 编写的下载脚本是

public function index($id)
    {

        $item = $this->music_m->get($id);
        if(count($item)){
            $path = $item->upload_path;

            if (file_exists($path)) {
                $item->noOfDownloads = $item->noOfDownloads + 1;
                $this->music_m->save($item, $id);
                header('Content-Description: File Transfer');
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment; filename='.basename($path));
                header('Content-Transfer-Encoding: binary');
                header('Expires: 0');
                header('Cache-Control: must-revalidate');
                header('Pragma: public');
                header('Content-Length: ' . filesize($path));
                ob_clean();
                flush();
                readfile($path);        
                exit;
            }else{
                echo "File doesnot exist";
                exit;
            }
        }else{
            echo "Requested music item doesn't exist in database";
            exit;
        }
    }

下载链接的 URL 格式为http://yourdomain.com/download/63,其中 63 是项目 ID。现在,当我从桌面单击链接时,它将下载文件而没有任何错误。但是当我从智能手机(android)点击相同的链接时,它给了我以下错误

ob_clean(): failed to delete buffer, no buffer to delete.

从某些手机上,它被下载但无法打开文件。有人知道我在哪里做错了吗?

4

0 回答 0