如何解决如何使用PHP脚本从网站将wav文件下载到本地服务器目录
|| 我想将此.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\')
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。