php實現遠程網絡文件下載到服務器指定目錄(方法二)


 

<?php
// maximum execution time in seconds
set_time_limit (24 * 60 * 60);
//if (!isset($_POST['submit'])) die();
// folder to save downloaded files to. must end with slash
$destination_folder = 'down/';
 
//$url = $_POST['url'];
$url="http://192.168.31.1/".urlencode(iconv("GB2312","UTF-8","測試.doc"));  //英文名字直接寫路徑就可以了
echo $url."<br>";
$newfname = $destination_folder . iconv("UTF-8","GB2312",urldecode(basename($url)));
echo $newfname;
//exit;
$file = fopen ($url, "rb");
if ($file) {
$newf = fopen ($newfname, "wb");
if ($newf)
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
?>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM