Uploading images without a file extension to WP

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];
// http://Green.cx (Allow Uploading of Images without Extension )
if ($ext==''){$ext='jpg'; $type='image/jpg';}
// End WordPress Core Hack
	return compact( 'ext', 'type' );
We will be happy to hear your thoughts

Leave a reply

Skip to toolbar