I need to encrypt and upload a file to Apache / PHP server using HTML5 FileReader API and CryptoJS
I have done the following successfully
But I was not able to send it to the server as an object File, because I already converted it to a text object, and I can not convert it back to a file. Below is my javascript file and server side snippet.
app.js var reader = new FileReader();
reader.onload = function (e) {
var encrypted = CryptoJS.AES.encrypt(e.target.result, password);
var data = new FormData($("#fileinfo")[0]);
data.append('file-0','data:application/octet-stream,' + encrypted);
$.ajax({
url: 'upload.php',
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function (data) {
}
});
};
<h / "> upload.php
<?php
var_dump($_FILES);
var_dump($_POST);
?>