I want to have a HTML form to send a file to my server by user. I need to know the exact time he started sending this file - not the time that the file was received (I can check received time e.g. by checking file modification time at server). This code should do this - when clicking "Submit" the current server time should be written to logsForSendingForm.txt and when the file receives time should be written to logsForReceivedForm.txt. Unfortunately, when sending the file, only the time when the file is received is written to logsForReceivedForm.txt - nothing is written to logsForReceivedForm.txt. What is interesting, if I don't select any file and click Submit, current time is written to both files.
If you don't know how to debug this, but you can suggest any other solution (maybe without AJAX), it's also OK, I don't need to do it like in this code.
<?php
if (isset($_POST['tickStart']))
{
file_put_contents('logsForSendingForm.txt', time() . "\n", FILE_APPEND);
}
elseif (!empty($_FILES))
{
file_put_contents('logsForReceivedForm.txt', time() . "\n", FILE_APPEND);
$f = $_FILES['file'];
$patch = str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']);
copy($f['tmp_name'], $patch.$f['name']);
}
?><!DOCTYPE html>
<html>
<head>
<script src='http://code.jquery.com/jquery-2.1.0.min.js'></script>
<script type='text/javascript'>
function sending()
{
$.ajax({
url: 'index.php',
type: 'POST',
data: { tickStart: true }
});
return true;
}
</script>
</head>
<body>
<form action='index.php' method='post' enctype='multipart/form-data'>
<input type='file' name='file'><br>
<input type='submit' name='submit' value='Submit' onsubmit="return sending()">
</form>
</body>
</html>