Hi!
I found this script on php.net, which allows you to ftp your files to a server.
While upload is in progress, the script displays:
1% uploaded
2% uploaded
3% uploaded etcetera…
Now, is there a way to alter this script in such a way that I get a progressbar?
The actual script:
<?php
$ftp_server = "some serrver";
$ftp_user_name = "blabnlalba";
$ftp_user_pass = "blablavla";
ob_end_flush();
$remote_file = 'NewsML_1.2-doc-Guidelines_1.00.pdf';
$local_file = 'NewsML_1.2-doc-Guidelines_1.00.pdf';
$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", $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);
?>
Any help would be greatly appreciated!!!
Regards,
Vic