Sorry to put a dampener on this topic, but...
First of all your download script wouldn't work as it would just flush as quick as possible. The script will continue to run through and finish even if the client has not yet fully downloaded.
The easiest way of doing an upload test, would be to use a combination of PHP and javascript (in the form of AJAX). Something along the lines of the following:
You will need 3 files:
1) An upload form
2) A start the timer script
3) A results form
The upload form: (I'm gonna use a jquery ajax call as it's less to type)
Code: Select all
<script>
function startUpload() {
$.get('starttimer.php',{},function () {
document.getElementById('myform').submit();
});
return false;
}
</script>
<form enctype="multipart/form-data" action="results.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" onclick="startUpload(); return false;" />
</form>
The start the timer script, just needs to set a session and log the time:
Code: Select all
<?php
session_start();
$_SESSION['uploadStartTime'] = mktime();
?>
The results form would be something like:
Code: Select all
<?php
session_start();
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
print "The number of seconds taken to upload {$_FILES['userfile']['size']}bytes was ";
print (mktime() - $_SESSION['uploadStartTime']);
}
?>
Now, the above code may or may not work out of the box, but it should give you a starting point. Basically, you make an ajax call to a script to make a note of the time on the server immediately prior to the upload beginning. That way you have something to compare against when the upload is complete, as the php script will not get executed until the upload has been completed.
Hope that helps