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
/home/usename/savewavfiles/
I need a PHP script to perform this task or a开发者_开发知识库ny sample code or tutorial would be a great help.
thanks, 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
:
$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')
);
精彩评论