l0ve2hat3 Posted January 13, 2009 Share Posted January 13, 2009 any ideas on how to calculate how long it will take to upload a file via ftp. and maybe a progress bar? Quote Link to comment https://forums.phpfreaks.com/topic/140603-ftp-upload-time/ Share on other sites More sharing options...
Caesar Posted January 13, 2009 Share Posted January 13, 2009 Javascript is your friend. Quote Link to comment https://forums.phpfreaks.com/topic/140603-ftp-upload-time/#findComment-735783 Share on other sites More sharing options...
l0ve2hat3 Posted January 13, 2009 Author Share Posted January 13, 2009 care to be more detailed? Quote Link to comment https://forums.phpfreaks.com/topic/140603-ftp-upload-time/#findComment-735784 Share on other sites More sharing options...
l0ve2hat3 Posted January 13, 2009 Author Share Posted January 13, 2009 any one? Quote Link to comment https://forums.phpfreaks.com/topic/140603-ftp-upload-time/#findComment-735793 Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 Google AJAX/PHP namely jQuery. That would be the only way to do it. Not sure on the time but the progress bar. If you want time, maybe flash would work. Quote Link to comment https://forums.phpfreaks.com/topic/140603-ftp-upload-time/#findComment-735794 Share on other sites More sharing options...
l0ve2hat3 Posted January 13, 2009 Author Share Posted January 13, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/140603-ftp-upload-time/#findComment-735841 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.