【问题标题】:want to download images from server想从服务器下载图片
【发布时间】:2011-05-17 21:08:17
【问题描述】:

我想将站点从共享托管服务器转移到专用服务器。当前服务器有文件夹,其中包括大约。 16000 张图片...我们无法使用 FTP 下载这么多图片。而且我没有 SSH 权限?我如何从这个共享托管服务器下载图像。

【问题讨论】:

  • @sonal 如果你没有 ssh 或 ftp 你有什么? HTTP?
  • 我有 FTP。但因为有大约。 16000张图片,服务器在很短的时间内就断开了。
  • 当前服务器在共享主机上?我问是因为您说“我如何从专用服务器下载图像”,而您说要从共享服务器转移到专用服务器。如果图片在您的 http-server 的 htdocs 中,您可以使用 wget 将它们下载到专用服务器。
  • 对不起。当前服务器是共享的。我想转移到专用服务器。
  • 你能给我脚本吗?

标签: php ftp file-transfer


【解决方案1】:

我们不能使用 FTP 来下载这么多图片

废话。 FTP(协议)完全能够下载 16000 个文件。如果您的 FTP 程序给您带来麻烦,只需选择一个更好的 FTP 程序。如果您可以处理命令行应用程序,wget 很好,因为它支持递归和延续。

【讨论】:

  • 也可能是 FTP 程序中的设置与站点不匹配
【解决方案2】:

除非它们位于 Web 应用程序服务器的 Web 根目录中,否则您将不走运。

【讨论】:

    【解决方案3】:

    全部压缩,改编自http://davidwalsh.name/create-zip-php

        <?php
    
            function create_zip($files = array(),$destination = '',$overwrite = false) {
              //if the zip file already exists and overwrite is false, return false
              if(file_exists($destination) && !$overwrite) { return false; }
              //vars
              $valid_files = array();
              //if files were passed in...
              if(is_array($files)) {
                //cycle through each file
                foreach($files as $file) {
                  //make sure the file exists
                  if(file_exists($file)) {
                    $valid_files[] = $file;
                  }
                }
              }
              //if we have good files...
              if(count($valid_files)) {
                //create the archive
                $zip = new ZipArchive();
                if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
                  return false;
                }
                //add the files
                foreach($valid_files as $file) {
                  $zip->addFile($file,$file);
                }
                //debug
                //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
    
                //close the zip -- done!
                $zip->close();
    
                //check to make sure the file exists
                return file_exists($destination);
              }
              else
              {
                return false;
              }
            }
    
    
        //glob images folder into an array
        foreach (glob("*.jpg") as $filename) {
            $files_to_zip[]='images/'.$filename;
        }
        //create the zip
        $result = create_zip($files_to_zip,'my-images.zip');
        if($result==true){echo'<a href="my-images.zip">Download Images</a>';
    }else{
    echo'Could not create zip';}
    
        ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-02
      • 2018-07-02
      • 2015-09-10
      相关资源
      最近更新 更多