2013-02-08 55 views
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); 

?>自動停止從下載服務器映像使用ftp_get

時遇到了完全500的圖像,但它僅下載高達200,然後它停止下載。在瀏覽器中,腳本一直運行,但圖像尚未下載。請提前幫助我,謝謝

回答

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);