Aaron
Aaron

Reputation: 1208

Handling File Uploads when a property is added from the Javascript File Object

When I receive files via POST I get the default name, type, size, tmp_name, error but the file I'm sending has additional information that I would like PHP to receive.

enter image description here

For example, above screenshot represents my file object in JavaScript. I added a property called newName which I would also like to receive in the global $_FILES variable in PHP, and then based on the newName property, upload the file on the newName.

Is this possible?

Upvotes: 0

Views: 396

Answers (1)

guest271314
guest271314

Reputation: 1

You can set the name property of a File object at a new File object

var file = new File(["abc"], "abc.txt", {type:"text/plain"});

console.log(file.name);

file = new File([file], "test", {type:file.type});

console.log(file.name);

Upvotes: 3

Related Questions