note 48517 added to function.ftp-nb-fput

From: Date: Tue, 28 Dec 2004 02:45:32 +0000
Subject: note 48517 added to function.ftp-nb-fput
Groups: php.notes 
Request: Send a blank email to php-notes+get-82381@lists.php.net to get a copy of this message
There is an easy way to check progress while uploading a file. Just use the ftell function to watch the position in the file handle. ftp_nb_fput will increment the position as the file is transferred. Example: <? $fh = fopen ($file_name, "r"); $ret = ftp_nb_fput ($ftp, $file_name, $fh, FTP_BINARY); while ($ret == FTP_MOREDATA) { print ftell ($fh)."\n"; $ret = ftp_nb_continue($ftp); } if ($ret != FTP_FINISHED) { print ("error uploading\n"); exit(1); } fclose($fh); ?> This will print out the number of bytes transferred thus far, every time the loop runs. Coverting this into a percentage is simply a matter of dividing the number of bytes transferred by the total size of the file. ---- Manual Page -- http://www.php.net/manual/en/function.ftp-nb-fput.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48517 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48517&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48517&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48517&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48517&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48517&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48517&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48517&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82381) next »