When converting the hexadecimal value, a PDF file, the file is corrupted.
This is the partial hex content of a simple pdf file I want to convert:
0x255044462D312E370D0A25B5B5B5B50D0A312030206F626A0D0A3C3C2F547970652F436174
Full string: jsfiddle, pastebin
This question is a continuation of this question, where I said that I have to do a data migration between two programs that handle files differently. The source program stores the files hex encoded in the database.
I could successfully extract and convert text files to binary files with the following code:
file_put_contents(
'document.pdf',
hex2bin(str_replace('0x', '', $hexPdfString))
);
But when I run this function on a pdf file or other binary file, it is corrupted.
My question is pretty much the same as this one but discussion over there was unfortunately discontinued.