News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

C. Sadeesh Kumar's Blog:
Smart File Type Detection Using PHP
August 29, 2011 @ 12:07:53

In a new post today C. Sadeesh Kumar has a quick tip to help your script detect file types without having to rely on the extension to be correct.

In most web applications today, there is a need to allow users to upload images, audio and video files. Sometimes, we also need to restrict certain types of files from being uploaded - an executable file being an obvious example. Security aside, one might also want to prevent users from misusing the upload facility, e.g. uploading copyrighted music files illegally and using the service to promote piracy! In this article, we'll look into a few ways in which we can achieve this.

The trick to his example is in using the Fileinfo PECL extension. With the help of this extension you can look inside the file and pick out the "magic bytes" (the first few bytes of a file) and see what MIME type the file really is. He includes a simple example of using the extension on a file and a file upload script that checks the type and handles the file accordingly.

0 comments voice your opinion now!
file type detection fileinfo extension pecl tutorial


blog comments powered by Disqus

Similar Posts

Pierre-Alain Joye's Blog: Zip 1.8.5, small bug fixes release

PHPBuilder.com: Remote objects and Zend_Amf

Gonzalo Ayuso's Blog: Using a stream wrapper to access CouchDb attachments with PHP

Christian Schaefer's Blog: Using PHP Web Scraper Goutte in a Console Task in a Silex project

Vidyut Luther's Blog: Adding Subscribers to Campaign Monitor Lists using PHP5 and SOAP


Community Events

Don't see your event here?
Let us know!


symfony2 voicesoftheelephpant laravel interview podcast release php7 conference community extension example series api library introduction opinion install version performance framework

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework