Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.