0
<?php
    //user name and password
    $ftp_server="";
    $ftp_user_name="";
    $ftp_user_pass="";

    // define some variables
    $local_file = 'localphoto/';
    $server_file `enter code here`= 'serverPhoto/';


// set up basic connection
$conn_id = ftp_connect($ftp_server);
if($conn_id)
{
    echo "connected";
}
{
 die("Couldn't connect to $ftp_server");
}

ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 18000);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

$contents = ftp_nlist($conn_id, $server_file); 
    foreach ($contents as $file) { 

           $cont = explode('/',$file);
           $ret = ftp_get($conn_id, $local_file.$cont[4], $file,  FTP_BINARY);              
}       


// close the connection
ftp_close($conn_id);

?>

我总共有 500 张图片,但它最多只能下载 200 张然后停止下载。在浏览器中,脚本一直在运行,但图像尚未下载。请帮助我提前谢谢

4

1 回答 1

0

你必须添加set_time_limit(0); 为了保持活动状态直到运行 php 脚本,我建议为浏览器回显某些内容以了解 php 不挂断并保持活动状态

  <?php
   set_time_limit(0);
   //user name and password
   $ftp_server="";
   $ftp_user_name="";
   $ftp_user_pass="";

   // define some variables
   $local_file = 'localphoto/';
   $server_file `enter code here`= 'serverPhoto/';


  // set up basic connection
  $conn_id = ftp_connect($ftp_server);
  if($conn_id)
  {
     echo "connected";
  }else
  {
   die("Couldn't connect to $ftp_server");
  }

  ftp_set_option($conn_id, FTP_TIMEOUT_SEC, 18000);

  // login with username and password
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

  $contents = ftp_nlist($conn_id, $server_file); 
  foreach ($contents as $file) { 

       $cont = explode('/',$file);
       $ret = ftp_get($conn_id, $local_file.$cont[4], $file,  FTP_BINARY);  
       echo $file."<br>";  //echo something for browser to know php not hangup and keeping Alive
       ob_flush();         
  }       


  // close the connection
  ftp_close($conn_id);
于 2013-02-08T09:06:52.653 回答