|
|
|
This function determines the correct extension of an image file. Getting types by the file extension is rather insecure, because it can be easily faked.
As an alternative, you can use mime_content_type() to detect the MIME type, even when the file is not an image.
|
<?php
function get_image_extension($filename)
{
if (function_exists('exif_imagetype'))
{
switch (exif_imagetype($filename))
{
case 1:
return 'gif';
case 2:
return 'jpg';
case 3:
return 'png';
case 4:
return 'swf';
case 5:
return 'psd';
case 6:
return 'bmp';
case 7:
return 'tiff';
case 8:
return 'tiff';
case 9:
return 'jpc';
case 10:
return 'jp2';
case 11:
return 'jpx';
case 12:
return 'jb2';
case 13:
return 'swc';
case 14:
return 'iff';
case 15:
return 'wbmp';
case 16:
return 'xbm';
default:
return false;
}
}
else
return false;
}
?> | |
If mime_content_type does not work for you, you can use this workaround:
taken from http://www.weberdev.com/mime-content-type
tree2054 using hotmail
04-Nov-2006 02:59
| <?php
if ( ! function_exists ( 'mime_content_type ' ) )
{
function mime_content_type ( $f )
{
return trim ( exec ('file -bi ' . escapeshellarg ( $f ) ) ) ;
}
}
?> | |
This workaround is for Linux users. If you use Windows, you have to install this application:
http://gnuwin32.sourceforge.net/packages/file.htm |
|
| Variable serialization and unserialization. Loading and saving variable structures
to and from file. Categories : Arrays, Filesystem, Variables, Strings, PHP | | | JSON File Upload Categories : PHP, AJAX, Filesystem | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | upload function using PHP's FTP abilities. Categories : PHP, Filesystem, HTML and PHP | | | phpEasySQL - Easily connect to your MySQL database with just 1 php file and 3 easy steps! Categories : Databases, PHP, MySQL, General SQL | | | Directory TreeView - File Manager & Explorer - FTP - Utility - PHP/HTML - Categories : PHP, Directories, FTP, Filesystem, HTML and PHP | | | Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem | | | Download manager - A PHP script for adding a download page to any site.It also enables you track the no. of downloads. Categories : PHP, Content Management, Filesystem, Databases, MySQL | | | a file explorer for the web, filesystem php php3 files dirs directories pictures files windows linux system list ls scripts Categories : PHP, URLs, Directories, Filesystem | | | Disk Usage, uses UNIX du command. Categories : Complete Programs, PHP, Filesystem | | | Show Source with Line Numbers Categories : PHP, Regexps, Filesystem | | | include php3 files Categories : Filesystem, PHP, Apache, Web Servers | | | grab directory listings into an array the example prints out each
subdirectory in the main dir - further work is to be performed on this one Categories : Filesystem, PHP, Directories, Search, Utilities | | | Moving folder hierarchy b/w server Categories : PHP, FTP, Filesystem | | | How to find the name of the current file? Categories : PHP, Filesystem, Strings | |
|
|