Possible Duplicate:
How to Check if File is ASCII or Binary in PHP
I have function which accepts either the name of the file of an image (i.e. normal string) or it can directly accept the image bytes as binary string. As returned by file_get_contents.
How can I differentiate between the two?
You could check if the input is composed only of printable characters. You can do that with ctype_print() if you’re only using ASCII characters 32 thru 126 and have zero expectations of Unicode characters:
You could also check if the argument is a valid image, or if a file with that name exists.
However it would be better and more reliable to create two separate functions: