Created
February 4, 2014 01:34
-
-
Save ahomu/8795930 to your computer and use it in GitHub Desktop.
画像アップロード時、レスポンスが返ってくるまでの時間を調べたい
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!empty($_FILES)) { | |
echo(json_encode($_FILES)); | |
} else { | |
?> | |
<!doctype html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1"> | |
<title>Test</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script> | |
$(function() { | |
var $form = $('#startForm'), | |
$iframe = $('#endFrame'), | |
$log = $('#log'), | |
start, end; | |
$form.on('submit', function() { | |
start = Date.now(); | |
}); | |
$iframe.on('load', function() { | |
end = Date.now(); | |
var resp = JSON.parse($iframe[0].contentWindow.document.body.innerHTML); | |
printTime(resp.photo.size); | |
}); | |
function printTime(size) { | |
var time = end - start; | |
$log.val($log.val() + time + ' ms (' + size + 'byte )\n'); | |
} | |
}); | |
</script> | |
</head> | |
<body> | |
<form id="startForm" action="/test.php" method="post" enctype="multipart/form-data" target="target"> | |
<input type="file" name="photo"> | |
<input type="submit" value="submit"> | |
</form> | |
<iframe id="endFrame" name="target" style="display: none;"> | |
</iframe> | |
<textarea id="log" rows="10" cols="30"></textarea> | |
</body> | |
</html> | |
<?php } | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment