note 107750 added to function.finfo-file

From: Date: Thu, 01 Mar 2012 18:31:52 +0000
Subject: note 107750 added to function.finfo-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-186451@lists.php.net to get a copy of this message
Well, i have a great probleam with that, MS Office 2007 extensions (pptx, xlsx, docx) do not have a default Mime type, they have "application/zip" mime type, so, to fix that, i do one little function to verify the extension. That function allow's you to be safe of fake extensions hack. <?php $arrayZips = array("application/zip", "application/x-zip", "application/x-zip-compressed"); $arrayExtensions = array(".pptx", ".docx", ".dotx", ".xlsx"); $file = 'path/to/file.xlsx'; $original_extension = (false === $pos = strrpos($file, '.')) ? '' : substr($file, $pos); $finfo = new finfo(FILEINFO_MIME); $type = $finfo->file($file); if (in_array($type, $arrayZips) && in_array($original_extension, $arrayExtensions)) { return $original_extension; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 201.37.247.38 ---- Manual Page -- http://www.php.net/manual/en/function.finfo-file.php Edit -- https://master.php.net/note/edit/107750 Del: integrated -- https://master.php.net/note/delete/107750/integrated Del: useless -- https://master.php.net/note/delete/107750/useless Del: bad code -- https://master.php.net/note/delete/107750/bad+code Del: spam -- https://master.php.net/note/delete/107750/spam Del: non-english -- https://master.php.net/note/delete/107750/non-english Del: in docs -- https://master.php.net/note/delete/107750/in+docs Del: other reasons-- https://master.php.net/note/delete/107750 Reject -- https://master.php.net/note/reject/107750 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186451) next »