PHP下载mp3文件, 图片等到本地

//下载文件
$url = ‘http://xxx.com/99248982.mp3‘;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
$rawdata = curl_exec($ch);
curl_close($ch);
$file_path = dirname(__FILE__) . ‘/temp/‘ . time() . ‘.mp3‘;
$fp = fopen($file_path, ‘w‘);
fwrite($fp, $rawdata);
fclose($fp);
// 上传到upyun
$cdn = uploadToUpyun($file_path, ‘audio/‘ . date(‘Ymd‘), $info[‘uuid‘] . ‘.mp3‘);

相关推荐