Now Reading
Uploading images without a file extension to WP
0

Uploading images without a file extension to WP

by Jason GreenJune 25, 2010

WP Core hacking

I used this code recently to hack wordpress’s core to allow image uploads that have no file extension.

I was getting a invalid file type security error and had tried all sorts of httaccess trickery to get it to work when I finally resorted to hacking the core of WordPress MU 3.0. This is pretty easy as I found out and only required me to add one line of code. Some of the issues I’m having are that the file size isn’t reported and neither is the┬ádimensions. Any advice or a way for me to make this into a plugin would be very nice, as I’ve never made a wordpress plugin before.

In wp-includes/functions.php find line #2359 and look for this code, and make it look like the code below.

function wp_check_filetype( $filename, $mimes = null ) {
	if ( empty($mimes) )
		$mimes = get_allowed_mime_types();
	$type = false;
	$ext = false;

	foreach ( $mimes as $ext_preg => $mime_match ) {
		$ext_preg = '!.(' . $ext_preg . ')$!i';
		if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
			$type = $mime_match;
			$ext = $ext_matches[1];
			break;
		}
	}
// http://Green.cx (Allow Uploading of Images without Extension )
if ($ext==''){$ext='jpg'; $type='image/jpg';}
// End WordPress Core Hack
	return compact( 'ext', 'type' );
}
About The Author
Jason Green
The writer and owner of Green Complex, Jason is an A+ Certified for Computer Hardware egghead and Eagle Scout since 1999 but has been building computers and programming for much longer. An enthusiast to say the least, his hobbies also include photography, video games, and reading. See his proficiencies on Smarterer.

You must log in to post a comment