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;



3 Comments to “Upload file with any extension in drupal”

  1. 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

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

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: