download audio with wget over php

2019-08-21 15:09发布

问题:

I am trying to download audio file over php. I have tried download it with curl and wget. here are examples:

<?php
  exec('wget http://static1.grsites.com/archive/sounds/cartoon/cartoon001.wav');
?>

How can I download it by using one of two mentioned methods.

回答1:

I think this should work for you:

<?php
    $url = 'http://static1.grsites.com/archive/sounds/cartoon/cartoon001.wav';
    header('Content-Type: audio/wav');
    header('Content-Disposition: inline;filename="name.wav"');
    header('Content-length: '.get_headers($url,1)['Content-Length']);
    header('Cache-Control: no-cache');
    header("Content-Transfer-Encoding: chunked");
    readfile("http://static1.grsites.com/archive/sounds/cartoon/cartoon001.wav");
?>


标签: php curl wget