I need to know if there is a way to retrieve the real file extension without parse the filename.
In my code I split the file using the function split(filename, ".")
then i get the last element of the array that the function returns.
Now, if I create a .pdf
file called, for example test_file.pdf
, the previous method works perfectly, but if i rename my file to test_file
(without extension) I cannot retrieve the extension even if I know that the file is a PDF.
For example, if i rename test_file.pdf to text_file.jpg how can I recognize that the file is still a pdf and not an image file with .jpg extension?
I would like to know if there is a way to obtain this information, maybe using file metadata or other information related to the file.
I'm looking for a Javascript solution because I have to check the extension when I upload the file using a form (client side) but even a Java solution could be fine, can you help me?
Thank you in advance!