PHP 8.5.0 Alpha 2 available for testing

Voting

: seven minus two?
(Example: nine)

The Note You're Voting On

jascha at bluestatedigital dot com
20 years ago
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.

<< Back to user notes page

To Top