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); } ?>
作者:Wicub
免责声明:文章、笔记等仅供分享、探讨、参考等学习之用,因此造成的任何后果概不负责。(如有错误、疏忽等问题,欢迎指正、讨论,谢谢)
本文版权归作者和博客园共有,欢迎转载,但请务必在文章页面明显位置给出原文连接,谢谢配合。