WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Get the correct extension and MIME types of an image, even when the filename is incorrect.
Categories : PHP, Filesystem, General SQL Click here to Update Your Picture
isaac mugisha
Date : Apr 28th 2007
Grade : 5 of 5 (graded 2 times)
Viewed : 12663
File : No file for this code example.
Images : No Images for this code example.
Search : More code by isaac mugisha
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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



How to find the name of the current file?
Categories : PHP, Filesystem, Strings
Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases
Variable serialization and unserialization. Loading and saving variable structures to and from file.
Categories : Arrays, Filesystem, Variables, Strings, PHP
Unix Disk Information with graphs
Categories : PHP, Shell Scripting, Filesystem
Search and Replace Text : Searches Files for Specified Text and Replaces It by a Given Text
Categories : PHP, PHP Classes, Search, Filesystem
Upload function using PHP's FTP abilities.
Categories : PHP, Filesystem, FTP
Differences between two files
Categories : PHP, Filesystem, Tip
include php3 files
Categories : Filesystem, PHP, Apache, Web Servers
Kasskooye($path) tell you the complete size of a folder
Categories : PHP, Algorithms, Utilities, Filesystem
Random Image Display
Categories : PHP, Filesystem, Graphics, 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
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL
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
Show Source with Line Numbers
Categories : PHP, Regexps, 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