从服务器端下载文件

家里的ADSL一直有问题,下载是超快的常常能达到1MB/S的速度可是上传速度一直不理想,可能是那个路由器的问题的,常常是只有1-5K/S左右,实在让人受不了,后来搜到了一个脚本,就直接从服务器端下载文件,省去了本地上传这个步骤,再加上服务端本来的网络就好,所以下载东西只是一下子的事,爽极了!

upload

下面就是原代码:

  1. <form method="post">
  2. <input name="url" size="50" />
  3. <input name="submit" type="submit" />
  4. </form>
  5. <?php
  6. // maximum execution time in seconds
  7. set_time_limit (24 * 60 * 60);
  8. if (!isset($_POST['submit'])) die();
  9. // folder to save downloaded files to. must end with slash
  10. $destination_folder = 'temp/';
  11.  
  12. $url = $_POST['url'];
  13. $newfname = $destination_folder . basename($url);
  14. $file = fopen ($url, "rb");
  15. if ($file) {
  16. $newf = fopen ($newfname, "wb");
  17. if ($newf)
  18. while(!feof($file)) {
  19. fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
  20. }
  21. }
  22. if ($file) {
  23. fclose($file);
  24. }
  25. if ($newf) {
  26. fclose($newf);
  27. }
  28. ?>

另存为upload.php上传到服务器,再新一个temp文件夹,权限为777就好了,下载的文件都在那里面的。

This entry was posted on 星期四, 七月 2nd, 2009 at 10:44 上午 and is filed under web2life. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment