upload file: how to store user local file creation date

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
jtandrea
User
Posts: 38

upload file: how to store user local file creation date

Post by jtandrea »

Hi all,
PHPMaker 2019.0.9 here.

What I want to accomplish is to store the file creation date
of the original file sent by the user.

As a matter of fact, the uploaded file doesn't inheritate the original file creation date
giving place to the date obtained at the end of the transfer/creation.

as an example:

say, I have a file
name = file1.txt
size = 150KB
creation date = 01/03/2019 10:25 (locally stored on user PC)

when the user uploads that file, I expect to store > 01/03/2019 10:25 < on the table

Should I use maybe client-side javascript to get the user local PC date?

thanks,
regards


arbei
User
Posts: 9409

Post by arbei »

You cannot get the file creation data by JavaScript on the client when you select the file so you cannot pass the date to the server side during upload. However, you can get the last modified date, see https://developer.mozilla.org/en-US/docs/Web/API/File.


jtandrea
User
Posts: 38

Post by jtandrea »

In my case the file selection button is referred to a field called: filename (using "File upload" "Multiple" option checked) .

In Client Scripts -> Startup Script, I tried to get the property lastModified (lastModifiedDate is deprecated) for the array of files without much luck.

just for testing purpose, in Client Scripts->Startup Script I added:

//btn-action is the id button when trying to upload file(s)

$("#btn-action").click(function() {
alert("1. clicked!");
var file = $("#x_filename").files;
alert("2. " + file[0].lastModified); //also tried with lastModifiedDate
});

It returns only the first alert. In fact, using the inspect feature over the button, it says the files property is empty (no elements).

To confirm what I was expecting to get, here's an additional working code (just copy/paste it) I executed:

<!DOCTYPE html>
<html>
<body>

<p>Click the button to create a File Upload Button.</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
var x = document.createElement("INPUT");
x.setAttribute("id", "fileitem");
x.setAttribute("type", "file");
x.setAttribute("multiple", true);
x.setAttribute("onchange", "GetInfo(this)");
document.body.appendChild(x);
}
function GetInfo(me) {
var file = me.files;
alert("file " + file[0].lastModifiedDate);

}
</script>

</body>
</html>

So I've no clue. Any help?

thanks,
regards


Webmaster
User
Posts: 9429

Post by Webmaster »

jtandrea wrote:
var file = $("#x_filename").files;

.files is not jQuery property, try $("#x_filename")[0].files.


jtandrea
User
Posts: 38

Post by jtandrea »

Webmaster wrote:
.files is not jQuery property, try $("#x_filename")[0].files.

sorry no, it doesn't work. when selecting one file, the alert always returns "undefined"

my code:

$("#btn-action").click(function() {
alert("1. clicked!");
var file = $("#x_filename")[0].files;
alert("2. " + file.name); //tried also with lastModified / lastModifiedDate
});

the inspect browser tool, after having selected one or more file, shows the files property as empty.
:-((

thanks,
regards


arbei
User
Posts: 9409

Post by arbei »

jtandrea wrote:
var file = me.files;
alert("file " + file[0].lastModifiedDate);


jtandrea
User
Posts: 38

Post by jtandrea »

I’m sorry, maybe I’m making some other mistake,
but it doesn’t work for me.

thanks anyway,
regards


Post Reply