Convert javascript date to work in PHP

1

I'm trying to capture the file date via javascript and send it to PHP.

Reason?

I want the date of the last file change.

$('#last_modified').val(arquivo[0].lastModified);

Variable file is:

<input type="file" name="teste" onchange="pegaArquivo(this.files)">

What returns me "1423493594000" to date: Mon Feb 09 2015 12:53:14 GMT -0200 (BRST)

However, when PHP reads this date it always returns the same: 12/31/1969

In php I do:

echo date ("d/m/Y", filectime($_POST['last_modified']));

Could you help me?

    
asked by anonymous 12.03.2015 / 18:38

1 answer

1

My mistake was to try to convert the team passed by direct javascript to PHP.

After the comments in the question itself, I made the requested changes and it is now working.

Follow the code that works for anyone who wants to see:

<script>
    function pegaArquivo(arquivoSelecionado) {
        if(arquivoSelecionado[0]){
            $('#last_modified').val(arquivoSelecionado[0].lastModified);
        }
    }
</script>

<input type="hidden" id="last_modified" name="last_modified" />
<input type="file" name="teste" onchange="pegaArquivo(this.files)"> <input type="submit">

In PHP:

echo 'Data do arquivo: <br>';
$dateInfo = getdate($_POST['last_modified']);
echo date ("d/m/Y", (int) $dateInfo[0]/1000);

The trick was to split the javascript team by 1000 as Javascript works with milliseconds and PHP with seconds.

Thank you all.

    
12.03.2015 / 19:59