Upload file with any extension in drupal

Drupal has a default extension list and files with those extension only allowed to upload. From administrator UI (administratot>file upload) we can add other extension. But if we want to modify the default list we can do that by modifying includes>file.inc

on file.inc there is a code block like the following,

$extensions = ”;    foreach ($user->roles as $rid => $name) {      $extensions .= ‘ ‘. variable_get(“upload_extensions_$rid”,      variable_get(‘upload_extensions_default’, ‘jpg jpeg gif png txt html doc xls pdf ppt pps odt ods odp’));    }

So we can add our desire extension.

There is also a validation function to check the files with allowed extension. We can disregard the validation.

function file_validate_extensions($file, $extensions) {

global $user;
$errors = array();
// Bypass validation for uid  = 1.

if ($user->uid != 1) {

$regex = ‘/\.(‘. ereg_replace(‘ +’, ‘|’, preg_quote($extensions)) .’)$/i’;

if (!preg_match($regex, $file->filename)) {

$errors[] = t(‘Only files with the following extensions are allowed: %files-allowed.’, array(‘%files-allowed’ => $extensions));



return $errors;