简体   繁体   English

如何使用PHP脚本从网站将WAV文件下载到本地服务器目录

[英]How to download a wav file from a web location to local server directory using PHP script

I would like to download this .WAV file to my webdirectory 我想将此.WAV文件下载到我的网站目录中

/home/usename/savewavfiles/ / home /用户名/ savewavfiles /

I need a PHP script to perform this task or any sample code or tutorial would be a great help. 我需要一个PHP脚本来执行此任务,否则任何示例代码或教程都会有很大的帮助。

thanks, sandeep 谢谢,sandeep

If you have curl enabled: 如果启用了卷曲:

<?php
/*
This is usefull when you are downloading big files, as it
will prevent time out of the script :
*/
set_time_limit(0);
ini_set('display_errors',true);//Just in case we get some errors, let us know....

$fp = fopen (dirname(__FILE__) . '/my.way', 'w+');//This is the file where we save the information
$ch = curl_init('http://www.kookoo.in/recordings/sandeepeecs/useraudiofile2277.wav');//Here is the file we are downloading
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>

Source 资源

you can do something like this: 您可以执行以下操作:

$link = 'http://remote.server.com/directory/sound_file.wav';
$my_dir = '/home/usename/savewavfiles/';

// get contents of the remote file
$remote_file = file_get_contents($link);

// create local file
$handle = fopen($mydir . basename($link), 'w');

// fill the local file with the contents from the remote server
fwrite($handle, $remote_file);

// close the local file
fclose($handle);

you can also use linux's wget : 您还可以使用linux的wget

$link = 'http://remote.server.com/directory/sound_file.wav';
shell_exec('wget '. $link);

That's easy for small ( < memory) files: 对于较小的(<内存)文件,这很容易:

file_put_contents(
    'localfile.wav',
    file_get_contents('http://example.org/remotefile.wav')
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM