|
|
|
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 |
|
| Dynamic WHERE CLAUSE depending on number of FORM FIELDS Categories : ODBC, General SQL, PHP, Complete Programs, Databases | | | PHP4 DirectoryIterator Class Categories : PHP, PHP Classes, Filesystem, Directories | | | Keep() - maintenance function for backup folders Categories : PHP, Filesystem, Maintenance | | | Contents Page - a script to build contents pages. Categories : Complete Programs, PHP, Utilities, Filesystem | | | Display list of files within current and subdirectories (recursively) showing
each file as an anchored link and each directory as a category header. Categories : Filesystem, Directories, Arrays, PHP | | | Single-file PHP news system with automatic folder structure creation Categories : PHP, Filesystem, Arrays | | | How to create an empty file? (touch) Categories : Filesystem, PHP | | | Multiple Search using PHP and Mysql Categories : PHP, Databases, General SQL, MySQL | | | Listing the 10 most recently updated files in a given dir by using last-
modified variable and printing to html with link to the file Categories : PHP, Directories, Filesystem | | | phpEasySQL - Easily connect to your MySQL database with just 1 php file and 3 easy steps! Categories : Databases, PHP, MySQL, General SQL | | | Unix Disk Information with graphs Categories : PHP, Shell Scripting, Filesystem | | | Save and restore files into postgresql database (PHP SCRIPT) PHP CLASS Categories : PHP, Databases, PostgreSQL, Filesystem | | | Differences between two files Categories : PHP, Filesystem, Tip | | | how can I read the entire contents of a file into a string? Categories : Filesystem, Strings, PHP | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | |
|
|
|