Jump to content

FTP upload time


l0ve2hat3

Recommended Posts

for those of you who may look at this later on, here is the solutions...

 

 


<?php
    ob_end_flush();
    $remote_file = 'remote.txt';
    $local_file = 'local.txt';

    $fp = fopen($local_file, 'r');
    $conn_id = ftp_connect($ftp_server);
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    $ret = ftp_nb_fput($conn_id, $remote_file, $fp, FTP_BINARY);
    while ($ret == FTP_MOREDATA) {
        // Establish a new connection to FTP server
        if(!isset($conn_id2)) {
            $conn_id2 = ftp_connect($ftp_server);
            $login_result2 = ftp_login($conn_id2, $ftp_user_name, $ftp_user_pass);
        }
       
        // Retreive size of uploaded file.
        if(isset($conn_id2)) {
            clearstatcache(); // <- this must be included!!
            $remote_file_size = ftp_size($conn_id2, $remote_file);
        }

       // Calculate upload progress
       $local_file_size  = filesize($local_file);
       if (isset($remote_file_size) && $remote_file_size > 0 ){
           $i = ($remote_file_size/$local_file_size)*100;
           printf("%d%% uploaded<br>", $i);
           flush();
       } 
        $ret = ftp_nb_continue($conn_id);
    }

    if ($ret != FTP_FINISHED) {
        print("There was an error uploading the file...<br>");
        exit(1);
    }
    else {
        print("Done.<br>");
    }
    fclose($fp);
?>

Link to comment
https://forums.phpfreaks.com/topic/140603-ftp-upload-time/#findComment-735841
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.