As already mentioned, there are javascript libraries that do the hard work for you. In general it is not worth getting into low-level details, as probably different versions of different browsers will be used you will have to deal with numerous compatibility issues.
Javascript Libraries
I recommend using the jQuery File Upload plugin. I've used it on some projects, even supporting multiple simultaneous uploads showing the results in a table. See the demo here .
Another alternative, especially to support older browsers, is uploadify . It has a fallback using Flash, so when the browser does not support the advanced upload features, it will automatically use this alternative.
Implementation that depends on PHP
On the other hand, if this functionality is important to your application and it will receive large uploads, you can use PHP's recent Session Upload Progress functionality, available from version 5.4.
Session Upload Progress does not affect the upload request, but allows you to monitor the upload through a variable placed in the session. Then you could make an Ajax from the page to retrieve the percentage of the upload, passing the field name by parameter. See the example:
<?php
//nome do elemento da sessão contendo um array de informações de upload
$key = ini_get("session.upload_progress.prefix") .
$_POST[ini_get("session.upload_progress.name")];
//recuperao vetor com informações de upload
$uploads_array = $_SESSION[$key];
//exibe as informações de um upload em específico
var_dump($uploads_array[$_POST["myField"]]);
?>
To enable the feature, enable the session.upload_progress.enabled
parameter in php.ini
.
See the documentation for more details.