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;



4 thoughts on “Upload file with any extension in drupal

  1. bet365 November 24, 2010 / 12:03 pm

    how are you I was luck to find your website in google
    your Topics is outstanding
    I learn a lot in your blog really thanks very much
    btw the theme of you website is really splendid
    where can find it

    • enamur November 28, 2010 / 5:31 pm

      Thank you very much. The theme is taken from the free template list of word press. You can find there a huge collection of themes.

  2. document October 21, 2012 / 7:40 pm

    Nice response in return of this difficulty with real
    arguments and explaining the whole thing on the topic of

  3. quora site analytics February 8, 2014 / 1:49 am

    Great blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple adjustements would really make my blog stand out.

    Please let me know where you got your design.
    Bless you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s