I want to send files via Ajax to the Server (upload) because of several benefits: no size limits, option to encrypt the data before sending it, combine data to 1MB pakages (slice one bigger file or combine several smaller files to one 1 MB pakage), (later) interrupt uploads and continue later. I've tried everything but whenever I find solutions in the web I allways have the problem that the data is incorrectly converted to utf8. Even "readAsDataUrl()" converts it incorrectly to utf8. As I know in the Mozilla developer website it is described, that this should create raw data which is just translated to base64. This is not true as I see. Using "readAsArrayBuffer()" does not help too, when the data is translated via "Uint8Array" to a string which now can be encrypted. And "readAsBinaryString()" is deprecated. There are several samples of code also on stackoverflow (ie Migrate FileReader ReadAsBinaryString() to ReadAsArrayBuffer() or ReadAsText()).
Maybe the issue is not in JavaScript but in PHP??? In one try I created a String from a blob (sliced file) via Int8Array and sent it to the server. In the PHP file I tried to create a file using the function "pack". It was also not encoded correctly but maybe there is an option to translate it to the right encoding??
Example: The Int8Array function (Int8Array(evt.target.result)) gave me the following data string: 80,75,3,4,20,0,0,8,0,0,-80,-109,73,79,94,-58,50 etc.
In PHP I tried to translate it in that way:
$tst_str = "80,75,3,4...";
$dec_arr = explode(",", $tst_str);
$bin_str = "";
foreach($dec_arr as $num) {
$bin_str .= pack("c", $num);
}
$fp = fopen("testfile.php", "w+");
fwrite($fp, $bin_str);
fclose($fp);
Is it possible to get the real raw data and be able to write 1:1 back in a file, without taking care about the encoding? AS I know in PHP it is possible. You just have to open the file via the read option "rb" and write it with the option "wb", that's it...