问题描述
||
我想将此.WAV文件下载到我的网站目录中
/ home /用户名/ savewavfiles /
我需要一个PHP脚本来执行此任务,否则任何示例代码或教程都会有很大的帮助。
谢谢,
桑迪普
解决方法
如果启用了卷曲:
<?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);
?>
资源
,您可以执行以下操作:
$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);
您还可以使用linux的wget
:
$link = \'http://remote.server.com/directory/sound_file.wav\';
shell_exec(\'wget \'. $link);
,对于较小的(<内存)文件,这很容易:
file_put_contents(
\'localfile.wav\',file_get_contents(\'http://example.org/remotefile.wav\')
);