How big would a typical file header be?

I’m using this code to get the MIME from the file header:

$fileInfo = new \finfo(FILEINFO_MIME);
$mimeType = $fileInfo->buffer(file_get_contents($_FILES[$formVar]['tmp_name']));

However, this could be a memory hog on large files as it reads the entire file into a string. I can easily truncate this but how many characters would you truncate it to to check a file header?

Can you not use http://php.net/manual/en/function.finfo-file.php instead of buffer to get the information without loading the entire file contents?

Ah yeah, didn’t know about that function! Thanks, I’ve just tested it and the memory used shows that it definitely just reads the header. Thanks a long, simple elegant solution!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.