如何使用PHP脚本将wav文件从web位置下载到本地服务器目录
我想把这个下载到我的网站目录 /home/usename/savewav文件/ 我需要一个PHP脚本来执行这项任务,或者任何示例代码或教程都会非常有帮助 谢谢,如何使用PHP脚本将wav文件从web位置下载到本地服务器目录,php,Php,我想把这个下载到我的网站目录 /home/usename/savewav文件/ 我需要一个PHP脚本来执行这项任务,或者任何示例代码或教程都会非常有帮助 谢谢, sandeep如果已启用卷曲: <?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
sandeep如果已启用卷曲:
<?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);
?>
如果已启用卷曲:
<?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);
您可以这样做:
$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);
这对于小(<内存)文件很容易:
这对于小(<内存)文件很容易:
这两个BTW中哪一个更好?我启用了curl,我的文件不会超过5MB。这两个都是很好的解决方案,我个人喜欢
file\u get\u contents
,但没有特别的原因:)这两个BTW中哪一个更好?我启用了curl,我的文件不会超过5MB。它们都是很好的解决方案,就我个人而言,我喜欢文件获取内容,但没有特别的原因:)嘿,这两个解决方案中哪一个是最好的,我的文件大小不会超过5MB。任何特定的原因都可以,但我更喜欢curl,它更快。看看这个基准测试:嘿,这两个解决方案中哪一个是最好的,我的文件大小不会超过5MB。任何特定的原因都可以,但我更喜欢curl,它更快。看看这个基准: