It seems you are asking if you can determine the type of file from its contents.
Most solutions will actually try to expand the file, but there are too many different types of files that can be reliably identifiable.
Most approaches use the first few bytes of a file to determine what they are.
, .
vs binary, . .
. this SO , JPG - , , .