web/drupal/includes/file.inc
author cavaliet@caf4f556-3d62-0410-8435-a86758001935
Fri, 21 Aug 2009 16:30:15 +0000
branchdrupal
changeset 75 a34abe7498a6
parent 74 0ff3ba646492
permissions -rw-r--r--
res/color/garland-5d26e3f9 added to the drupal folder in order to see the css
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
74
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     1
<?php
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     2
// $Id: file.inc,v 1.121.2.7 2009/06/09 10:37:38 goba Exp $
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     3
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     4
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     5
 * @file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     6
 * API for handling file uploads and server file management.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     7
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     8
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
     9
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    10
 * @defgroup file File interface
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    11
 * @{
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    12
 * Common file handling functions.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    13
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    14
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    15
define('FILE_DOWNLOADS_PUBLIC', 1);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    16
define('FILE_DOWNLOADS_PRIVATE', 2);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    17
define('FILE_CREATE_DIRECTORY', 1);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    18
define('FILE_MODIFY_PERMISSIONS', 2);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    19
define('FILE_EXISTS_RENAME', 0);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    20
define('FILE_EXISTS_REPLACE', 1);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    21
define('FILE_EXISTS_ERROR', 2);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    22
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    23
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    24
 * A files status can be one of two values: temporary or permanent. The status
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    25
 * for each file Drupal manages is stored in the {files} tables. If the status
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    26
 * is temporary Drupal's file garbage collection will delete the file and
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    27
 * remove it from the files table after a set period of time.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    28
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    29
 * If you wish to add custom statuses for use by contrib modules please expand as
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    30
 * binary flags and consider the first 8 bits reserved. (0,1,2,4,8,16,32,64,128)
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    31
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    32
define('FILE_STATUS_TEMPORARY', 0);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    33
define('FILE_STATUS_PERMANENT', 1);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    34
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    35
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    36
 * Create the download path to a file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    37
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    38
 * @param $path A string containing the path of the file to generate URL for.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    39
 * @return A string containing a URL that can be used to download the file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    40
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    41
function file_create_url($path) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    42
  // Strip file_directory_path from $path. We only include relative paths in urls.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    43
  if (strpos($path, file_directory_path() .'/') === 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    44
    $path = trim(substr($path, strlen(file_directory_path())), '\\/');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    45
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    46
  switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    47
    case FILE_DOWNLOADS_PUBLIC:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    48
      return $GLOBALS['base_url'] .'/'. file_directory_path() .'/'. str_replace('\\', '/', $path);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    49
    case FILE_DOWNLOADS_PRIVATE:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    50
      return url('system/files/'. $path, array('absolute' => TRUE));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    51
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    52
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    53
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    54
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    55
 * Make sure the destination is a complete path and resides in the file system
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    56
 * directory, if it is not prepend the file system directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    57
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    58
 * @param $dest A string containing the path to verify. If this value is
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    59
 *   omitted, Drupal's 'files' directory will be used.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    60
 * @return A string containing the path to file, with file system directory
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    61
 *   appended if necessary, or FALSE if the path is invalid (i.e. outside the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    62
 *   configured 'files' or temp directories).
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    63
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    64
function file_create_path($dest = 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    65
  $file_path = file_directory_path();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    66
  if (!$dest) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    67
    return $file_path;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    68
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    69
  // file_check_location() checks whether the destination is inside the Drupal files directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    70
  if (file_check_location($dest, $file_path)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    71
    return $dest;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    72
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    73
  // check if the destination is instead inside the Drupal temporary files directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    74
  else if (file_check_location($dest, file_directory_temp())) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    75
    return $dest;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    76
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    77
  // Not found, try again with prefixed directory path.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    78
  else if (file_check_location($file_path .'/'. $dest, $file_path)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    79
    return $file_path .'/'. $dest;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    80
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    81
  // File not found.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    82
  return FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    83
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    84
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    85
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    86
 * Check that the directory exists and is writable. Directories need to
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    87
 * have execute permissions to be considered a directory by FTP servers, etc.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    88
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    89
 * @param $directory A string containing the name of a directory path.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    90
 * @param $mode A Boolean value to indicate if the directory should be created
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    91
 *   if it does not exist or made writable if it is read-only.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    92
 * @param $form_item An optional string containing the name of a form item that
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    93
 *   any errors will be attached to. This is useful for settings forms that
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    94
 *   require the user to specify a writable directory. If it can't be made to
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    95
 *   work, a form error will be set preventing them from saving the settings.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    96
 * @return FALSE when directory not found, or TRUE when directory exists.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    97
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    98
function file_check_directory(&$directory, $mode = 0, $form_item = NULL) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
    99
  $directory = rtrim($directory, '/\\');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   100
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   101
  // Check if directory exists.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   102
  if (!is_dir($directory)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   103
    if (($mode & FILE_CREATE_DIRECTORY) && @mkdir($directory)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   104
      drupal_set_message(t('The directory %directory has been created.', array('%directory' => $directory)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   105
      @chmod($directory, 0775); // Necessary for non-webserver users.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   106
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   107
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   108
      if ($form_item) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   109
        form_set_error($form_item, t('The directory %directory does not exist.', array('%directory' => $directory)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   110
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   111
      return FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   112
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   113
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   114
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   115
  // Check to see if the directory is writable.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   116
  if (!is_writable($directory)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   117
    if (($mode & FILE_MODIFY_PERMISSIONS) && @chmod($directory, 0775)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   118
      drupal_set_message(t('The permissions of directory %directory have been changed to make it writable.', array('%directory' => $directory)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   119
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   120
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   121
      form_set_error($form_item, t('The directory %directory is not writable', array('%directory' => $directory)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   122
      watchdog('file system', 'The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => $directory), WATCHDOG_ERROR);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   123
      return FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   124
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   125
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   126
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   127
  if ((file_directory_path() == $directory || file_directory_temp() == $directory) && !is_file("$directory/.htaccess")) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   128
    $htaccess_lines = "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks";
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   129
    if (($fp = fopen("$directory/.htaccess", 'w')) && fputs($fp, $htaccess_lines)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   130
      fclose($fp);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   131
      chmod($directory .'/.htaccess', 0664);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   132
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   133
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   134
      $variables = array('%directory' => $directory, '!htaccess' => '<br />'. nl2br(check_plain($htaccess_lines)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   135
      form_set_error($form_item, t("Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   136
      watchdog('security', "Security warning: Couldn't write .htaccess file. Please create a .htaccess file in your %directory directory which contains the following lines: <code>!htaccess</code>", $variables, WATCHDOG_ERROR);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   137
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   138
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   139
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   140
  return TRUE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   141
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   142
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   143
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   144
 * Checks path to see if it is a directory, or a dir/file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   145
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   146
 * @param $path A string containing a file path. This will be set to the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   147
 *   directory's path.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   148
 * @return If the directory is not in a Drupal writable directory, FALSE is
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   149
 *   returned. Otherwise, the base name of the path is returned.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   150
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   151
function file_check_path(&$path) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   152
  // Check if path is a directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   153
  if (file_check_directory($path)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   154
    return '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   155
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   156
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   157
  // Check if path is a possible dir/file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   158
  $filename = basename($path);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   159
  $path = dirname($path);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   160
  if (file_check_directory($path)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   161
    return $filename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   162
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   163
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   164
  return FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   165
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   166
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   167
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   168
 * Check if a file is really located inside $directory. Should be used to make
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   169
 * sure a file specified is really located within the directory to prevent
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   170
 * exploits.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   171
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   172
 * @code
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   173
 *   // Returns FALSE:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   174
 *   file_check_location('/www/example.com/files/../../../etc/passwd', '/www/example.com/files');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   175
 * @endcode
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   176
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   177
 * @param $source A string set to the file to check.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   178
 * @param $directory A string where the file should be located.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   179
 * @return 0 for invalid path or the real path of the source.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   180
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   181
function file_check_location($source, $directory = '') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   182
  $check = realpath($source);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   183
  if ($check) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   184
    $source = $check;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   185
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   186
  else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   187
    // This file does not yet exist
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   188
    $source = realpath(dirname($source)) .'/'. basename($source);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   189
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   190
  $directory = realpath($directory);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   191
  if ($directory && strpos($source, $directory) !== 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   192
    return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   193
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   194
  return $source;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   195
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   196
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   197
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   198
 * Copies a file to a new location. This is a powerful function that in many ways
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   199
 * performs like an advanced version of copy().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   200
 * - Checks if $source and $dest are valid and readable/writable.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   201
 * - Performs a file copy if $source is not equal to $dest.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   202
 * - If file already exists in $dest either the call will error out, replace the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   203
 *   file or rename the file based on the $replace parameter.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   204
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   205
 * @param $source A string specifying the file location of the original file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   206
 *   This parameter will contain the resulting destination filename in case of
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   207
 *   success.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   208
 * @param $dest A string containing the directory $source should be copied to.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   209
 *   If this value is omitted, Drupal's 'files' directory will be used.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   210
 * @param $replace Replace behavior when the destination file already exists.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   211
 *   - FILE_EXISTS_REPLACE - Replace the existing file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   212
 *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   213
 *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   214
 * @return True for success, FALSE for failure.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   215
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   216
function file_copy(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   217
  $dest = file_create_path($dest);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   218
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   219
  $directory = $dest;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   220
  $basename = file_check_path($directory);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   221
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   222
  // Make sure we at least have a valid directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   223
  if ($basename === FALSE) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   224
    $source = is_object($source) ? $source->filepath : $source;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   225
    drupal_set_message(t('The selected file %file could not be uploaded, because the destination %directory is not properly configured.', array('%file' => $source, '%directory' => $dest)), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   226
    watchdog('file system', 'The selected file %file could not be uploaded, because the destination %directory could not be found, or because its permissions do not allow the file to be written.', array('%file' => $source, '%directory' => $dest), WATCHDOG_ERROR);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   227
    return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   228
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   229
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   230
  // Process a file upload object.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   231
  if (is_object($source)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   232
    $file = $source;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   233
    $source = $file->filepath;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   234
    if (!$basename) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   235
      $basename = $file->filename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   236
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   237
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   238
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   239
  $source = realpath($source);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   240
  if (!file_exists($source)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   241
    drupal_set_message(t('The selected file %file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.', array('%file' => $source)), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   242
    return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   243
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   244
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   245
  // If the destination file is not specified then use the filename of the source file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   246
  $basename = $basename ? $basename : basename($source);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   247
  $dest = $directory .'/'. $basename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   248
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   249
  // Make sure source and destination filenames are not the same, makes no sense
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   250
  // to copy it if they are. In fact copying the file will most likely result in
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   251
  // a 0 byte file. Which is bad. Real bad.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   252
  if ($source != realpath($dest)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   253
    if (!$dest = file_destination($dest, $replace)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   254
      drupal_set_message(t('The selected file %file could not be copied, because a file by that name already exists in the destination.', array('%file' => $source)), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   255
      return FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   256
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   257
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   258
    if (!@copy($source, $dest)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   259
      drupal_set_message(t('The selected file %file could not be copied.', array('%file' => $source)), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   260
      return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   261
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   262
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   263
    // Give everyone read access so that FTP'd users or
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   264
    // non-webserver users can see/read these files,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   265
    // and give group write permissions so group members
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   266
    // can alter files uploaded by the webserver.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   267
    @chmod($dest, 0664);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   268
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   269
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   270
  if (isset($file) && is_object($file)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   271
    $file->filename = $basename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   272
    $file->filepath = $dest;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   273
    $source = $file;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   274
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   275
  else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   276
    $source = $dest;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   277
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   278
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   279
  return 1; // Everything went ok.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   280
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   281
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   282
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   283
 * Determines the destination path for a file depending on how replacement of
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   284
 * existing files should be handled.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   285
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   286
 * @param $destination A string specifying the desired path.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   287
 * @param $replace Replace behavior when the destination file already exists.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   288
 *   - FILE_EXISTS_REPLACE - Replace the existing file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   289
 *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   290
 *     unique
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   291
 *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   292
 * @return The destination file path or FALSE if the file already exists and
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   293
 *   FILE_EXISTS_ERROR was specified.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   294
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   295
function file_destination($destination, $replace) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   296
  if (file_exists($destination)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   297
    switch ($replace) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   298
      case FILE_EXISTS_RENAME:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   299
        $basename = basename($destination);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   300
        $directory = dirname($destination);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   301
        $destination = file_create_filename($basename, $directory);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   302
        break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   303
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   304
      case FILE_EXISTS_ERROR:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   305
        drupal_set_message(t('The selected file %file could not be copied, because a file by that name already exists in the destination.', array('%file' => $destination)), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   306
        return FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   307
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   308
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   309
  return $destination;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   310
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   311
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   312
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   313
 * Moves a file to a new location.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   314
 * - Checks if $source and $dest are valid and readable/writable.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   315
 * - Performs a file move if $source is not equal to $dest.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   316
 * - If file already exists in $dest either the call will error out, replace the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   317
 *   file or rename the file based on the $replace parameter.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   318
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   319
 * @param $source A string specifying the file location of the original file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   320
 *   This parameter will contain the resulting destination filename in case of
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   321
 *   success.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   322
 * @param $dest A string containing the directory $source should be copied to.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   323
 *   If this value is omitted, Drupal's 'files' directory will be used.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   324
 * @param $replace Replace behavior when the destination file already exists.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   325
 *   - FILE_EXISTS_REPLACE - Replace the existing file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   326
 *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   327
 *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   328
 * @return True for success, FALSE for failure.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   329
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   330
function file_move(&$source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   331
  $path_original = is_object($source) ? $source->filepath : $source;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   332
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   333
  if (file_copy($source, $dest, $replace)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   334
    $path_current = is_object($source) ? $source->filepath : $source;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   335
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   336
    if ($path_original == $path_current || file_delete($path_original)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   337
      return 1;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   338
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   339
    drupal_set_message(t('The removal of the original file %file has failed.', array('%file' => $path_original)), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   340
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   341
  return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   342
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   343
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   344
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   345
 * Munge the filename as needed for security purposes. For instance the file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   346
 * name "exploit.php.pps" would become "exploit.php_.pps".
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   347
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   348
 * @param $filename The name of a file to modify.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   349
 * @param $extensions A space separated list of extensions that should not
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   350
 *   be altered.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   351
 * @param $alerts Whether alerts (watchdog, drupal_set_message()) should be
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   352
 *   displayed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   353
 * @return $filename The potentially modified $filename.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   354
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   355
function file_munge_filename($filename, $extensions, $alerts = TRUE) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   356
  $original = $filename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   357
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   358
  // Allow potentially insecure uploads for very savvy users and admin
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   359
  if (!variable_get('allow_insecure_uploads', 0)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   360
    $whitelist = array_unique(explode(' ', trim($extensions)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   361
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   362
    // Split the filename up by periods. The first part becomes the basename
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   363
    // the last part the final extension.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   364
    $filename_parts = explode('.', $filename);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   365
    $new_filename = array_shift($filename_parts); // Remove file basename.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   366
    $final_extension = array_pop($filename_parts); // Remove final extension.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   367
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   368
    // Loop through the middle parts of the name and add an underscore to the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   369
    // end of each section that could be a file extension but isn't in the list
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   370
    // of allowed extensions.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   371
    foreach ($filename_parts as $filename_part) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   372
      $new_filename .= '.'. $filename_part;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   373
      if (!in_array($filename_part, $whitelist) && preg_match("/^[a-zA-Z]{2,5}\d?$/", $filename_part)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   374
        $new_filename .= '_';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   375
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   376
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   377
    $filename = $new_filename .'.'. $final_extension;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   378
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   379
    if ($alerts && $original != $filename) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   380
      drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', array('%filename' => $filename)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   381
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   382
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   383
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   384
  return $filename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   385
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   386
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   387
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   388
 * Undo the effect of upload_munge_filename().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   389
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   390
 * @param $filename string filename
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   391
 * @return string
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   392
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   393
function file_unmunge_filename($filename) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   394
  return str_replace('_.', '.', $filename);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   395
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   396
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   397
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   398
 * Create a full file path from a directory and filename. If a file with the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   399
 * specified name already exists, an alternative will be used.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   400
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   401
 * @param $basename string filename
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   402
 * @param $directory string directory
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   403
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   404
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   405
function file_create_filename($basename, $directory) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   406
  $dest = $directory .'/'. $basename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   407
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   408
  if (file_exists($dest)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   409
    // Destination file already exists, generate an alternative.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   410
    if ($pos = strrpos($basename, '.')) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   411
      $name = substr($basename, 0, $pos);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   412
      $ext = substr($basename, $pos);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   413
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   414
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   415
      $name = $basename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   416
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   417
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   418
    $counter = 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   419
    do {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   420
      $dest = $directory .'/'. $name .'_'. $counter++ . $ext;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   421
    } while (file_exists($dest));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   422
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   423
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   424
  return $dest;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   425
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   426
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   427
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   428
 * Delete a file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   429
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   430
 * @param $path A string containing a file path.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   431
 * @return TRUE for success, FALSE for failure.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   432
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   433
function file_delete($path) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   434
  if (is_file($path)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   435
    return unlink($path);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   436
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   437
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   438
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   439
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   440
 * Determine total disk space used by a single user or the whole filesystem.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   441
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   442
 * @param $uid
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   443
 *   An optional user id. A NULL value returns the total space used
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   444
 *   by all files.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   445
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   446
function file_space_used($uid = NULL) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   447
  if (isset($uid)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   448
    return (int) db_result(db_query('SELECT SUM(filesize) FROM {files} WHERE uid = %d', $uid));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   449
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   450
  return (int) db_result(db_query('SELECT SUM(filesize) FROM {files}'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   451
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   452
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   453
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   454
 * Saves a file upload to a new location. The source file is validated as a
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   455
 * proper upload and handled as such.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   456
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   457
 * The file will be added to the files table as a temporary file. Temporary files
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   458
 * are periodically cleaned. To make the file permanent file call
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   459
 * file_set_status() to change its status.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   460
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   461
 * @param $source
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   462
 *   A string specifying the name of the upload field to save.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   463
 * @param $validators
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   464
 *   An optional, associative array of callback functions used to validate the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   465
 *   file. The keys are function names and the values arrays of callback
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   466
 *   parameters which will be passed in after the file object. The
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   467
 *   functions should return an array of error messages; an empty array
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   468
 *   indicates that the file passed validation. The functions will be called in
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   469
 *   the order specified.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   470
 * @param $dest
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   471
 *   A string containing the directory $source should be copied to. If this is
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   472
 *   not provided or is not writable, the temporary directory will be used.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   473
 * @param $replace
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   474
 *   A boolean indicating whether an existing file of the same name in the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   475
 *   destination directory should overwritten. A false value will generate a
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   476
 *   new, unique filename in the destination directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   477
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   478
 *   An object containing the file information, or 0 in the event of an error.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   479
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   480
function file_save_upload($source, $validators = array(), $dest = FALSE, $replace = FILE_EXISTS_RENAME) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   481
  global $user;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   482
  static $upload_cache;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   483
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   484
  // Add in our check of the the file name length.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   485
  $validators['file_validate_name_length'] = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   486
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   487
  // Return cached objects without processing since the file will have
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   488
  // already been processed and the paths in _FILES will be invalid.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   489
  if (isset($upload_cache[$source])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   490
    return $upload_cache[$source];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   491
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   492
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   493
  // If a file was uploaded, process it.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   494
  if (isset($_FILES['files']) && $_FILES['files']['name'][$source] && is_uploaded_file($_FILES['files']['tmp_name'][$source])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   495
    // Check for file upload errors and return FALSE if a
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   496
    // lower level system error occurred.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   497
    switch ($_FILES['files']['error'][$source]) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   498
      // @see http://php.net/manual/en/features.file-upload.errors.php
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   499
      case UPLOAD_ERR_OK:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   500
        break;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   501
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   502
      case UPLOAD_ERR_INI_SIZE:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   503
      case UPLOAD_ERR_FORM_SIZE:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   504
        drupal_set_message(t('The file %file could not be saved, because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $source, '%maxsize' => format_size(file_upload_max_size()))), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   505
        return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   506
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   507
      case UPLOAD_ERR_PARTIAL:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   508
      case UPLOAD_ERR_NO_FILE:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   509
        drupal_set_message(t('The file %file could not be saved, because the upload did not complete.', array('%file' => $source)), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   510
        return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   511
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   512
        // Unknown error
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   513
      default:
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   514
        drupal_set_message(t('The file %file could not be saved. An unknown error has occurred.', array('%file' => $source)), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   515
        return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   516
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   517
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   518
    // Build the list of non-munged extensions.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   519
    // @todo: this should not be here. we need to figure out the right place.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   520
    $extensions = '';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   521
    foreach ($user->roles as $rid => $name) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   522
      $extensions .= ' '. variable_get("upload_extensions_$rid",
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   523
      variable_get('upload_extensions_default', 'jpg jpeg gif png txt html doc xls pdf ppt pps odt ods odp'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   524
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   525
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   526
    // Begin building file object.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   527
    $file = new stdClass();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   528
    $file->filename = file_munge_filename(trim(basename($_FILES['files']['name'][$source]), '.'), $extensions);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   529
    $file->filepath = $_FILES['files']['tmp_name'][$source];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   530
    $file->filemime = file_get_mimetype($file->filename);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   531
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   532
    // Rename potentially executable files, to help prevent exploits.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   533
    if (preg_match('/\.(php|pl|py|cgi|asp|js)$/i', $file->filename) && (substr($file->filename, -4) != '.txt')) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   534
      $file->filemime = 'text/plain';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   535
      $file->filepath .= '.txt';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   536
      $file->filename .= '.txt';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   537
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   538
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   539
    // If the destination is not provided, or is not writable, then use the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   540
    // temporary directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   541
    if (empty($dest) || file_check_path($dest) === FALSE) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   542
      $dest = file_directory_temp();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   543
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   544
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   545
    $file->source = $source;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   546
    $file->destination = file_destination(file_create_path($dest .'/'. $file->filename), $replace);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   547
    $file->filesize = $_FILES['files']['size'][$source];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   548
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   549
    // Call the validation functions.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   550
    $errors = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   551
    foreach ($validators as $function => $args) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   552
      array_unshift($args, $file);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   553
      $errors = array_merge($errors, call_user_func_array($function, $args));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   554
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   555
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   556
    // Check for validation errors.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   557
    if (!empty($errors)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   558
      $message = t('The selected file %name could not be uploaded.', array('%name' => $file->filename));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   559
      if (count($errors) > 1) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   560
        $message .= '<ul><li>'. implode('</li><li>', $errors) .'</li></ul>';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   561
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   562
      else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   563
        $message .= ' '. array_pop($errors);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   564
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   565
      form_set_error($source, $message);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   566
      return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   567
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   568
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   569
    // Move uploaded files from PHP's upload_tmp_dir to Drupal's temporary directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   570
    // This overcomes open_basedir restrictions for future file operations.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   571
    $file->filepath = $file->destination;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   572
    if (!move_uploaded_file($_FILES['files']['tmp_name'][$source], $file->filepath)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   573
      form_set_error($source, t('File upload error. Could not move uploaded file.'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   574
      watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->filepath));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   575
      return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   576
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   577
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   578
    // If we made it this far it's safe to record this file in the database.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   579
    $file->uid = $user->uid;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   580
    $file->status = FILE_STATUS_TEMPORARY;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   581
    $file->timestamp = time();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   582
    drupal_write_record('files', $file);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   583
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   584
    // Add file to the cache.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   585
    $upload_cache[$source] = $file;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   586
    return $file;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   587
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   588
  return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   589
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   590
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   591
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   592
 * Check for files with names longer than we can store in the database.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   593
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   594
 * @param $file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   595
 *   A Drupal file object.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   596
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   597
 *   An array. If the file name is too long, it will contain an error message.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   598
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   599
function file_validate_name_length($file) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   600
  $errors = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   601
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   602
  if (strlen($file->filename) > 255) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   603
    $errors[] = t('Its name exceeds the 255 characters limit. Please rename the file and try again.');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   604
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   605
  return $errors;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   606
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   607
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   608
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   609
 * Check that the filename ends with an allowed extension. This check is not
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   610
 * enforced for the user #1.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   611
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   612
 * @param $file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   613
 *   A Drupal file object.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   614
 * @param $extensions
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   615
 *   A string with a space separated
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   616
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   617
 *   An array. If the file extension is not allowed, it will contain an error message.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   618
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   619
function file_validate_extensions($file, $extensions) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   620
  global $user;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   621
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   622
  $errors = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   623
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   624
  // Bypass validation for uid  = 1.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   625
  if ($user->uid != 1) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   626
    $regex = '/\.('. ereg_replace(' +', '|', preg_quote($extensions)) .')$/i';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   627
    if (!preg_match($regex, $file->filename)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   628
      $errors[] = t('Only files with the following extensions are allowed: %files-allowed.', array('%files-allowed' => $extensions));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   629
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   630
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   631
  return $errors;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   632
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   633
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   634
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   635
 * Check that the file's size is below certain limits. This check is not
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   636
 * enforced for the user #1.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   637
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   638
 * @param $file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   639
 *   A Drupal file object.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   640
 * @param $file_limit
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   641
 *   An integer specifying the maximum file size in bytes. Zero indicates that
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   642
 *   no limit should be enforced.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   643
 * @param $user_limit
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   644
 *   An integer specifying the maximum number of bytes the user is allowed. Zero
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   645
 *   indicates that no limit should be enforced.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   646
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   647
 *   An array. If the file size exceeds limits, it will contain an error message.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   648
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   649
function file_validate_size($file, $file_limit = 0, $user_limit = 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   650
  global $user;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   651
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   652
  $errors = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   653
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   654
  // Bypass validation for uid  = 1.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   655
  if ($user->uid != 1) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   656
    if ($file_limit && $file->filesize > $file_limit) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   657
      $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   658
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   659
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   660
    // Save a query by only calling file_space_used() when a limit is provided.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   661
    if ($user_limit && (file_space_used($user->uid) + $file->filesize) > $user_limit) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   662
      $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   663
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   664
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   665
  return $errors;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   666
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   667
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   668
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   669
 * Check that the file is recognized by image_get_info() as an image.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   670
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   671
 * @param $file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   672
 *   A Drupal file object.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   673
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   674
 *   An array. If the file is not an image, it will contain an error message.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   675
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   676
function file_validate_is_image(&$file) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   677
  $errors = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   678
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   679
  $info = image_get_info($file->filepath);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   680
  if (!$info || empty($info['extension'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   681
    $errors[] = t('Only JPEG, PNG and GIF images are allowed.');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   682
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   683
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   684
  return $errors;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   685
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   686
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   687
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   688
 * If the file is an image verify that its dimensions are within the specified
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   689
 * maximum and minimum dimensions. Non-image files will be ignored.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   690
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   691
 * @param $file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   692
 *   A Drupal file object. This function may resize the file affecting its size.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   693
 * @param $maximum_dimensions
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   694
 *   An optional string in the form WIDTHxHEIGHT e.g. '640x480' or '85x85'. If
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   695
 *   an image toolkit is installed the image will be resized down to these
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   696
 *   dimensions. A value of 0 indicates no restriction on size, so resizing
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   697
 *   will be attempted.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   698
 * @param $minimum_dimensions
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   699
 *   An optional string in the form WIDTHxHEIGHT. This will check that the image
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   700
 *   meets a minimum size. A value of 0 indicates no restriction.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   701
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   702
 *   An array. If the file is an image and did not meet the requirements, it
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   703
 *   will contain an error message.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   704
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   705
function file_validate_image_resolution(&$file, $maximum_dimensions = 0, $minimum_dimensions = 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   706
  $errors = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   707
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   708
  // Check first that the file is an image.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   709
  if ($info = image_get_info($file->filepath)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   710
    if ($maximum_dimensions) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   711
      // Check that it is smaller than the given dimensions.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   712
      list($width, $height) = explode('x', $maximum_dimensions);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   713
      if ($info['width'] > $width || $info['height'] > $height) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   714
        // Try to resize the image to fit the dimensions.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   715
        if (image_get_toolkit() && image_scale($file->filepath, $file->filepath, $width, $height)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   716
          drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions)));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   717
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   718
          // Clear the cached filesize and refresh the image information.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   719
          clearstatcache();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   720
          $info = image_get_info($file->filepath);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   721
          $file->filesize = $info['file_size'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   722
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   723
        else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   724
          $errors[] = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $maximum_dimensions));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   725
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   726
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   727
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   728
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   729
    if ($minimum_dimensions) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   730
      // Check that it is larger than the given dimensions.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   731
      list($width, $height) = explode('x', $minimum_dimensions);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   732
      if ($info['width'] < $width || $info['height'] < $height) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   733
        $errors[] = t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => $minimum_dimensions));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   734
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   735
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   736
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   737
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   738
  return $errors;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   739
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   740
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   741
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   742
 * Save a string to the specified destination.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   743
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   744
 * @param $data A string containing the contents of the file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   745
 * @param $dest A string containing the destination location.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   746
 * @param $replace Replace behavior when the destination file already exists.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   747
 *   - FILE_EXISTS_REPLACE - Replace the existing file
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   748
 *   - FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   749
 *   - FILE_EXISTS_ERROR - Do nothing and return FALSE.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   750
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   751
 * @return A string containing the resulting filename or 0 on error
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   752
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   753
function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   754
  $temp = file_directory_temp();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   755
  // On Windows, tempnam() requires an absolute path, so we use realpath().
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   756
  $file = tempnam(realpath($temp), 'file');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   757
  if (!$fp = fopen($file, 'wb')) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   758
    drupal_set_message(t('The file could not be created.'), 'error');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   759
    return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   760
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   761
  fwrite($fp, $data);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   762
  fclose($fp);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   763
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   764
  if (!file_move($file, $dest, $replace)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   765
    return 0;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   766
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   767
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   768
  return $file;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   769
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   770
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   771
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   772
 * Set the status of a file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   773
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   774
 * @param file A Drupal file object
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   775
 * @param status A status value to set the file to.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   776
 * @return FALSE on failure, TRUE on success and $file->status will contain the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   777
 *     status.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   778
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   779
function file_set_status(&$file, $status) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   780
  if (db_query('UPDATE {files} SET status = %d WHERE fid = %d', $status, $file->fid)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   781
    $file->status = $status;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   782
    return TRUE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   783
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   784
  return FALSE;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   785
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   786
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   787
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   788
 * Transfer file using http to client. Pipes a file through Drupal to the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   789
 * client.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   790
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   791
 * @param $source File to transfer.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   792
 * @param $headers An array of http headers to send along with file.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   793
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   794
function file_transfer($source, $headers) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   795
  if (ob_get_level()) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   796
    ob_end_clean();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   797
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   798
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   799
  foreach ($headers as $header) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   800
    // To prevent HTTP header injection, we delete new lines that are
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   801
    // not followed by a space or a tab.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   802
    // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   803
    $header = preg_replace('/\r?\n(?!\t| )/', '', $header);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   804
    drupal_set_header($header);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   805
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   806
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   807
  $source = file_create_path($source);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   808
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   809
  // Transfer file in 1024 byte chunks to save memory usage.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   810
  if ($fd = fopen($source, 'rb')) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   811
    while (!feof($fd)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   812
      print fread($fd, 1024);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   813
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   814
    fclose($fd);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   815
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   816
  else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   817
    drupal_not_found();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   818
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   819
  exit();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   820
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   821
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   822
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   823
 * Call modules that implement hook_file_download() to find out if a file is
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   824
 * accessible and what headers it should be transferred with. If a module
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   825
 * returns -1 drupal_access_denied() will be returned. If one or more modules
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   826
 * returned headers the download will start with the returned headers. If no
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   827
 * modules respond drupal_not_found() will be returned.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   828
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   829
function file_download() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   830
  // Merge remainder of arguments from GET['q'], into relative file path.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   831
  $args = func_get_args();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   832
  $filepath = implode('/', $args);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   833
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   834
  // Maintain compatibility with old ?file=paths saved in node bodies.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   835
  if (isset($_GET['file'])) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   836
    $filepath =  $_GET['file'];
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   837
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   838
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   839
  if (file_exists(file_create_path($filepath))) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   840
    $headers = module_invoke_all('file_download', $filepath);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   841
    if (in_array(-1, $headers)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   842
      return drupal_access_denied();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   843
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   844
    if (count($headers)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   845
      file_transfer($filepath, $headers);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   846
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   847
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   848
  return drupal_not_found();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   849
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   850
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   851
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   852
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   853
 * Finds all files that match a given mask in a given directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   854
 * Directories and files beginning with a period are excluded; this
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   855
 * prevents hidden files and directories (such as SVN working directories)
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   856
 * from being scanned.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   857
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   858
 * @param $dir
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   859
 *   The base directory for the scan, without trailing slash.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   860
 * @param $mask
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   861
 *   The regular expression of the files to find.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   862
 * @param $nomask
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   863
 *   An array of files/directories to ignore.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   864
 * @param $callback
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   865
 *   The callback function to call for each match.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   866
 * @param $recurse
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   867
 *   When TRUE, the directory scan will recurse the entire tree
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   868
 *   starting at the provided directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   869
 * @param $key
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   870
 *   The key to be used for the returned array of files. Possible
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   871
 *   values are "filename", for the path starting with $dir,
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   872
 *   "basename", for the basename of the file, and "name" for the name
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   873
 *   of the file without an extension.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   874
 * @param $min_depth
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   875
 *   Minimum depth of directories to return files from.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   876
 * @param $depth
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   877
 *   Current depth of recursion. This parameter is only used internally and should not be passed.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   878
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   879
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   880
 *   An associative array (keyed on the provided key) of objects with
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   881
 *   "path", "basename", and "name" members corresponding to the
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   882
 *   matching files.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   883
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   884
function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $callback = 0, $recurse = TRUE, $key = 'filename', $min_depth = 0, $depth = 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   885
  $key = (in_array($key, array('filename', 'basename', 'name')) ? $key : 'filename');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   886
  $files = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   887
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   888
  if (is_dir($dir) && $handle = opendir($dir)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   889
    while (FALSE !== ($file = readdir($handle))) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   890
      if (!in_array($file, $nomask) && $file[0] != '.') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   891
        if (is_dir("$dir/$file") && $recurse) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   892
          // Give priority to files in this folder by merging them in after any subdirectory files.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   893
          $files = array_merge(file_scan_directory("$dir/$file", $mask, $nomask, $callback, $recurse, $key, $min_depth, $depth + 1), $files);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   894
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   895
        elseif ($depth >= $min_depth && ereg($mask, $file)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   896
          // Always use this match over anything already set in $files with the same $$key.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   897
          $filename = "$dir/$file";
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   898
          $basename = basename($file);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   899
          $name = substr($basename, 0, strrpos($basename, '.'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   900
          $files[$$key] = new stdClass();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   901
          $files[$$key]->filename = $filename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   902
          $files[$$key]->basename = $basename;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   903
          $files[$$key]->name = $name;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   904
          if ($callback) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   905
            $callback($filename);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   906
          }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   907
        }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   908
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   909
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   910
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   911
    closedir($handle);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   912
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   913
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   914
  return $files;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   915
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   916
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   917
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   918
 * Determine the default temporary directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   919
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   920
 * @return A string containing a temp directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   921
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   922
function file_directory_temp() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   923
  $temporary_directory = variable_get('file_directory_temp', NULL);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   924
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   925
  if (is_null($temporary_directory)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   926
    $directories = array();
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   927
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   928
    // Has PHP been set with an upload_tmp_dir?
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   929
    if (ini_get('upload_tmp_dir')) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   930
      $directories[] = ini_get('upload_tmp_dir');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   931
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   932
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   933
    // Operating system specific dirs.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   934
    if (substr(PHP_OS, 0, 3) == 'WIN') {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   935
      $directories[] = 'c:\\windows\\temp';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   936
      $directories[] = 'c:\\winnt\\temp';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   937
      $path_delimiter = '\\';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   938
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   939
    else {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   940
      $directories[] = '/tmp';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   941
      $path_delimiter = '/';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   942
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   943
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   944
    foreach ($directories as $directory) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   945
      if (!$temporary_directory && is_dir($directory)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   946
        $temporary_directory = $directory;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   947
      }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   948
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   949
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   950
    // if a directory has been found, use it, otherwise default to 'files/tmp' or 'files\\tmp';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   951
    $temporary_directory = $temporary_directory ? $temporary_directory : file_directory_path() . $path_delimiter .'tmp';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   952
    variable_set('file_directory_temp', $temporary_directory);
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   953
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   954
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   955
  return $temporary_directory;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   956
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   957
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   958
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   959
 * Determine the default 'files' directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   960
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   961
 * @return A string containing the path to Drupal's 'files' directory.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   962
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   963
function file_directory_path() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   964
  return variable_get('file_directory_path', conf_path() .'/files');
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   965
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   966
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   967
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   968
 * Determine the maximum file upload size by querying the PHP settings.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   969
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   970
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   971
 *   A file size limit in bytes based on the PHP upload_max_filesize and post_max_size
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   972
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   973
function file_upload_max_size() {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   974
  static $max_size = -1;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   975
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   976
  if ($max_size < 0) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   977
    $upload_max = parse_size(ini_get('upload_max_filesize'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   978
    $post_max = parse_size(ini_get('post_max_size'));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   979
    $max_size = ($upload_max < $post_max) ? $upload_max : $post_max;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   980
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   981
  return $max_size;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   982
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   983
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   984
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   985
 * Determine an Internet Media Type, or MIME type from a filename.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   986
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   987
 * @param $filename
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   988
 *   Name of the file, including extension.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   989
 * @param $mapping
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   990
 *   An optional array of extension to media type mappings in the form
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   991
 *   'extension1|extension2|...' => 'type'.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   992
 *
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   993
 * @return
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   994
 *   The internet media type registered for the extension or application/octet-stream for unknown extensions.
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   995
 */
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   996
function file_get_mimetype($filename, $mapping = NULL) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   997
  if (!is_array($mapping)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   998
    $mapping = variable_get('mime_extension_mapping', array(
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
   999
      'ez' => 'application/andrew-inset',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1000
      'atom' => 'application/atom',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1001
      'atomcat' => 'application/atomcat+xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1002
      'atomsrv' => 'application/atomserv+xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1003
      'cap|pcap' => 'application/cap',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1004
      'cu' => 'application/cu-seeme',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1005
      'tsp' => 'application/dsptype',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1006
      'spl' => 'application/x-futuresplash',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1007
      'hta' => 'application/hta',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1008
      'jar' => 'application/java-archive',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1009
      'ser' => 'application/java-serialized-object',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1010
      'class' => 'application/java-vm',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1011
      'hqx' => 'application/mac-binhex40',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1012
      'cpt' => 'image/x-corelphotopaint',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1013
      'nb' => 'application/mathematica',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1014
      'mdb' => 'application/msaccess',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1015
      'doc|dot' => 'application/msword',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1016
      'bin' => 'application/octet-stream',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1017
      'oda' => 'application/oda',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1018
      'ogg|ogx' => 'application/ogg',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1019
      'pdf' => 'application/pdf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1020
      'key' => 'application/pgp-keys',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1021
      'pgp' => 'application/pgp-signature',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1022
      'prf' => 'application/pics-rules',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1023
      'ps|ai|eps' => 'application/postscript',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1024
      'rar' => 'application/rar',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1025
      'rdf' => 'application/rdf+xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1026
      'rss' => 'application/rss+xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1027
      'rtf' => 'application/rtf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1028
      'smi|smil' => 'application/smil',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1029
      'wpd' => 'application/wordperfect',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1030
      'wp5' => 'application/wordperfect5.1',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1031
      'xhtml|xht' => 'application/xhtml+xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1032
      'xml|xsl' => 'application/xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1033
      'zip' => 'application/zip',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1034
      'cdy' => 'application/vnd.cinderella',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1035
      'kml' => 'application/vnd.google-earth.kml+xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1036
      'kmz' => 'application/vnd.google-earth.kmz',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1037
      'xul' => 'application/vnd.mozilla.xul+xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1038
      'xls|xlb|xlt' => 'application/vnd.ms-excel',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1039
      'cat' => 'application/vnd.ms-pki.seccat',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1040
      'stl' => 'application/vnd.ms-pki.stl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1041
      'ppt|pps' => 'application/vnd.ms-powerpoint',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1042
      'odc' => 'application/vnd.oasis.opendocument.chart',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1043
      'odb' => 'application/vnd.oasis.opendocument.database',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1044
      'odf' => 'application/vnd.oasis.opendocument.formula',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1045
      'odg' => 'application/vnd.oasis.opendocument.graphics',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1046
      'otg' => 'application/vnd.oasis.opendocument.graphics-template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1047
      'odi' => 'application/vnd.oasis.opendocument.image',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1048
      'odp' => 'application/vnd.oasis.opendocument.presentation',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1049
      'otp' => 'application/vnd.oasis.opendocument.presentation-template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1050
      'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1051
      'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1052
      'odt' => 'application/vnd.oasis.opendocument.text',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1053
      'odm' => 'application/vnd.oasis.opendocument.text-master',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1054
      'ott' => 'application/vnd.oasis.opendocument.text-template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1055
      'oth' => 'application/vnd.oasis.opendocument.text-web',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1056
      'docm' => 'application/vnd.ms-word.document.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1057
      'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1058
      'dotm' => 'application/vnd.ms-word.template.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1059
      'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1060
      'potm' => 'application/vnd.ms-powerpoint.template.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1061
      'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1062
      'ppam' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1063
      'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1064
      'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1065
      'pptm' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1066
      'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1067
      'xlam' => 'application/vnd.ms-excel.addin.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1068
      'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1069
      'xlsm' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1070
      'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1071
      'xltm' => 'application/vnd.ms-excel.template.macroEnabled.12',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1072
      'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1073
      'cod' => 'application/vnd.rim.cod',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1074
      'mmf' => 'application/vnd.smaf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1075
      'sdc' => 'application/vnd.stardivision.calc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1076
      'sds' => 'application/vnd.stardivision.chart',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1077
      'sda' => 'application/vnd.stardivision.draw',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1078
      'sdd' => 'application/vnd.stardivision.impress',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1079
      'sdf' => 'application/vnd.stardivision.math',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1080
      'sdw' => 'application/vnd.stardivision.writer',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1081
      'sgl' => 'application/vnd.stardivision.writer-global',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1082
      'sxc' => 'application/vnd.sun.xml.calc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1083
      'stc' => 'application/vnd.sun.xml.calc.template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1084
      'sxd' => 'application/vnd.sun.xml.draw',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1085
      'std' => 'application/vnd.sun.xml.draw.template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1086
      'sxi' => 'application/vnd.sun.xml.impress',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1087
      'sti' => 'application/vnd.sun.xml.impress.template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1088
      'sxm' => 'application/vnd.sun.xml.math',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1089
      'sxw' => 'application/vnd.sun.xml.writer',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1090
      'sxg' => 'application/vnd.sun.xml.writer.global',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1091
      'stw' => 'application/vnd.sun.xml.writer.template',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1092
      'sis' => 'application/vnd.symbian.install',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1093
      'vsd' => 'application/vnd.visio',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1094
      'wbxml' => 'application/vnd.wap.wbxml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1095
      'wmlc' => 'application/vnd.wap.wmlc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1096
      'wmlsc' => 'application/vnd.wap.wmlscriptc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1097
      'wk' => 'application/x-123',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1098
      '7z' => 'application/x-7z-compressed',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1099
      'abw' => 'application/x-abiword',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1100
      'dmg' => 'application/x-apple-diskimage',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1101
      'bcpio' => 'application/x-bcpio',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1102
      'torrent' => 'application/x-bittorrent',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1103
      'cab' => 'application/x-cab',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1104
      'cbr' => 'application/x-cbr',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1105
      'cbz' => 'application/x-cbz',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1106
      'cdf' => 'application/x-cdf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1107
      'vcd' => 'application/x-cdlink',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1108
      'pgn' => 'application/x-chess-pgn',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1109
      'cpio' => 'application/x-cpio',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1110
      'csh' => 'text/x-csh',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1111
      'deb|udeb' => 'application/x-debian-package',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1112
      'dcr|dir|dxr' => 'application/x-director',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1113
      'dms' => 'application/x-dms',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1114
      'wad' => 'application/x-doom',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1115
      'dvi' => 'application/x-dvi',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1116
      'rhtml' => 'application/x-httpd-eruby',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1117
      'flac' => 'application/x-flac',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1118
      'pfa|pfb|gsf|pcf|pcf.Z' => 'application/x-font',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1119
      'mm' => 'application/x-freemind',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1120
      'gnumeric' => 'application/x-gnumeric',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1121
      'sgf' => 'application/x-go-sgf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1122
      'gcf' => 'application/x-graphing-calculator',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1123
      'gtar|tgz|taz' => 'application/x-gtar',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1124
      'hdf' => 'application/x-hdf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1125
      'phtml|pht|php' => 'application/x-httpd-php',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1126
      'phps' => 'application/x-httpd-php-source',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1127
      'php3' => 'application/x-httpd-php3',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1128
      'php3p' => 'application/x-httpd-php3-preprocessed',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1129
      'php4' => 'application/x-httpd-php4',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1130
      'ica' => 'application/x-ica',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1131
      'ins|isp' => 'application/x-internet-signup',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1132
      'iii' => 'application/x-iphone',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1133
      'iso' => 'application/x-iso9660-image',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1134
      'jnlp' => 'application/x-java-jnlp-file',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1135
      'js' => 'application/x-javascript',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1136
      'jmz' => 'application/x-jmol',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1137
      'chrt' => 'application/x-kchart',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1138
      'kil' => 'application/x-killustrator',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1139
      'skp|skd|skt|skm' => 'application/x-koan',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1140
      'kpr|kpt' => 'application/x-kpresenter',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1141
      'ksp' => 'application/x-kspread',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1142
      'kwd|kwt' => 'application/x-kword',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1143
      'latex' => 'application/x-latex',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1144
      'lha' => 'application/x-lha',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1145
      'lyx' => 'application/x-lyx',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1146
      'lzh' => 'application/x-lzh',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1147
      'lzx' => 'application/x-lzx',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1148
      'frm|maker|frame|fm|fb|book|fbdoc' => 'application/x-maker',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1149
      'mif' => 'application/x-mif',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1150
      'wmd' => 'application/x-ms-wmd',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1151
      'wmz' => 'application/x-ms-wmz',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1152
      'com|exe|bat|dll' => 'application/x-msdos-program',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1153
      'msi' => 'application/x-msi',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1154
      'nc' => 'application/x-netcdf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1155
      'pac' => 'application/x-ns-proxy-autoconfig',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1156
      'nwc' => 'application/x-nwc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1157
      'o' => 'application/x-object',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1158
      'oza' => 'application/x-oz-application',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1159
      'p7r' => 'application/x-pkcs7-certreqresp',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1160
      'crl' => 'application/x-pkcs7-crl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1161
      'pyc|pyo' => 'application/x-python-code',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1162
      'qtl' => 'application/x-quicktimeplayer',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1163
      'rpm' => 'application/x-redhat-package-manager',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1164
      'sh' => 'text/x-sh',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1165
      'shar' => 'application/x-shar',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1166
      'swf|swfl' => 'application/x-shockwave-flash',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1167
      'sit|sitx' => 'application/x-stuffit',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1168
      'sv4cpio' => 'application/x-sv4cpio',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1169
      'sv4crc' => 'application/x-sv4crc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1170
      'tar' => 'application/x-tar',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1171
      'tcl' => 'application/x-tcl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1172
      'gf' => 'application/x-tex-gf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1173
      'pk' => 'application/x-tex-pk',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1174
      'texinfo|texi' => 'application/x-texinfo',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1175
      '~|%|bak|old|sik' => 'application/x-trash',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1176
      't|tr|roff' => 'application/x-troff',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1177
      'man' => 'application/x-troff-man',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1178
      'me' => 'application/x-troff-me',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1179
      'ms' => 'application/x-troff-ms',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1180
      'ustar' => 'application/x-ustar',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1181
      'src' => 'application/x-wais-source',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1182
      'wz' => 'application/x-wingz',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1183
      'crt' => 'application/x-x509-ca-cert',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1184
      'xcf' => 'application/x-xcf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1185
      'fig' => 'application/x-xfig',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1186
      'xpi' => 'application/x-xpinstall',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1187
      'au|snd' => 'audio/basic',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1188
      'mid|midi|kar' => 'audio/midi',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1189
      'mpga|mpega|mp2|mp3|m4a' => 'audio/mpeg',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1190
      'm3u' => 'audio/x-mpegurl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1191
      'oga|spx' => 'audio/ogg',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1192
      'sid' => 'audio/prs.sid',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1193
      'aif|aiff|aifc' => 'audio/x-aiff',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1194
      'gsm' => 'audio/x-gsm',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1195
      'wma' => 'audio/x-ms-wma',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1196
      'wax' => 'audio/x-ms-wax',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1197
      'ra|rm|ram' => 'audio/x-pn-realaudio',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1198
      'ra' => 'audio/x-realaudio',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1199
      'pls' => 'audio/x-scpls',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1200
      'sd2' => 'audio/x-sd2',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1201
      'wav' => 'audio/x-wav',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1202
      'alc' => 'chemical/x-alchemy',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1203
      'cac|cache' => 'chemical/x-cache',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1204
      'csf' => 'chemical/x-cache-csf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1205
      'cbin|cascii|ctab' => 'chemical/x-cactvs-binary',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1206
      'cdx' => 'chemical/x-cdx',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1207
      'cer' => 'chemical/x-cerius',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1208
      'c3d' => 'chemical/x-chem3d',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1209
      'chm' => 'chemical/x-chemdraw',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1210
      'cif' => 'chemical/x-cif',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1211
      'cmdf' => 'chemical/x-cmdf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1212
      'cml' => 'chemical/x-cml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1213
      'cpa' => 'chemical/x-compass',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1214
      'bsd' => 'chemical/x-crossfire',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1215
      'csml|csm' => 'chemical/x-csml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1216
      'ctx' => 'chemical/x-ctx',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1217
      'cxf|cef' => 'chemical/x-cxf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1218
      'emb|embl' => 'chemical/x-embl-dl-nucleotide',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1219
      'spc' => 'chemical/x-galactic-spc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1220
      'inp|gam|gamin' => 'chemical/x-gamess-input',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1221
      'fch|fchk' => 'chemical/x-gaussian-checkpoint',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1222
      'cub' => 'chemical/x-gaussian-cube',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1223
      'gau|gjc|gjf' => 'chemical/x-gaussian-input',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1224
      'gal' => 'chemical/x-gaussian-log',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1225
      'gcg' => 'chemical/x-gcg8-sequence',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1226
      'gen' => 'chemical/x-genbank',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1227
      'hin' => 'chemical/x-hin',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1228
      'istr|ist' => 'chemical/x-isostar',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1229
      'jdx|dx' => 'chemical/x-jcamp-dx',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1230
      'kin' => 'chemical/x-kinemage',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1231
      'mcm' => 'chemical/x-macmolecule',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1232
      'mmd|mmod' => 'chemical/x-macromodel-input',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1233
      'mol' => 'chemical/x-mdl-molfile',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1234
      'rd' => 'chemical/x-mdl-rdfile',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1235
      'rxn' => 'chemical/x-mdl-rxnfile',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1236
      'sd|sdf' => 'chemical/x-mdl-sdfile',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1237
      'tgf' => 'chemical/x-mdl-tgf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1238
      'mcif' => 'chemical/x-mmcif',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1239
      'mol2' => 'chemical/x-mol2',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1240
      'b' => 'chemical/x-molconn-Z',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1241
      'gpt' => 'chemical/x-mopac-graph',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1242
      'mop|mopcrt|mpc|dat|zmt' => 'chemical/x-mopac-input',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1243
      'moo' => 'chemical/x-mopac-out',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1244
      'mvb' => 'chemical/x-mopac-vib',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1245
      'asn' => 'chemical/x-ncbi-asn1-spec',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1246
      'prt|ent' => 'chemical/x-ncbi-asn1-ascii',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1247
      'val|aso' => 'chemical/x-ncbi-asn1-binary',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1248
      'pdb|ent' => 'chemical/x-pdb',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1249
      'ros' => 'chemical/x-rosdal',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1250
      'sw' => 'chemical/x-swissprot',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1251
      'vms' => 'chemical/x-vamas-iso14976',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1252
      'vmd' => 'chemical/x-vmd',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1253
      'xtel' => 'chemical/x-xtel',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1254
      'xyz' => 'chemical/x-xyz',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1255
      'gif' => 'image/gif',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1256
      'ief' => 'image/ief',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1257
      'jpeg|jpg|jpe' => 'image/jpeg',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1258
      'pcx' => 'image/pcx',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1259
      'png' => 'image/png',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1260
      'svg|svgz' => 'image/svg+xml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1261
      'tiff|tif' => 'image/tiff',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1262
      'djvu|djv' => 'image/vnd.djvu',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1263
      'wbmp' => 'image/vnd.wap.wbmp',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1264
      'ras' => 'image/x-cmu-raster',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1265
      'cdr' => 'image/x-coreldraw',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1266
      'pat' => 'image/x-coreldrawpattern',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1267
      'cdt' => 'image/x-coreldrawtemplate',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1268
      'ico' => 'image/x-icon',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1269
      'art' => 'image/x-jg',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1270
      'jng' => 'image/x-jng',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1271
      'bmp' => 'image/x-ms-bmp',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1272
      'psd' => 'image/x-photoshop',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1273
      'pnm' => 'image/x-portable-anymap',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1274
      'pbm' => 'image/x-portable-bitmap',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1275
      'pgm' => 'image/x-portable-graymap',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1276
      'ppm' => 'image/x-portable-pixmap',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1277
      'rgb' => 'image/x-rgb',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1278
      'xbm' => 'image/x-xbitmap',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1279
      'xpm' => 'image/x-xpixmap',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1280
      'xwd' => 'image/x-xwindowdump',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1281
      'eml' => 'message/rfc822',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1282
      'igs|iges' => 'model/iges',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1283
      'msh|mesh|silo' => 'model/mesh',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1284
      'wrl|vrml' => 'model/vrml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1285
      'ics|icz' => 'text/calendar',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1286
      'css' => 'text/css',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1287
      'csv' => 'text/csv',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1288
      '323' => 'text/h323',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1289
      'html|htm|shtml' => 'text/html',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1290
      'uls' => 'text/iuls',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1291
      'mml' => 'text/mathml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1292
      'asc|txt|text|pot' => 'text/plain',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1293
      'rtx' => 'text/richtext',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1294
      'sct|wsc' => 'text/scriptlet',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1295
      'tm|ts' => 'text/texmacs',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1296
      'tsv' => 'text/tab-separated-values',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1297
      'jad' => 'text/vnd.sun.j2me.app-descriptor',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1298
      'wml' => 'text/vnd.wap.wml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1299
      'wmls' => 'text/vnd.wap.wmlscript',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1300
      'bib' => 'text/x-bibtex',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1301
      'boo' => 'text/x-boo',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1302
      'h++|hpp|hxx|hh' => 'text/x-c++hdr',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1303
      'c++|cpp|cxx|cc' => 'text/x-c++src',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1304
      'h' => 'text/x-chdr',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1305
      'htc' => 'text/x-component',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1306
      'c' => 'text/x-csrc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1307
      'd' => 'text/x-dsrc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1308
      'diff|patch' => 'text/x-diff',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1309
      'hs' => 'text/x-haskell',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1310
      'java' => 'text/x-java',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1311
      'lhs' => 'text/x-literate-haskell',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1312
      'moc' => 'text/x-moc',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1313
      'p|pas' => 'text/x-pascal',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1314
      'gcd' => 'text/x-pcs-gcd',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1315
      'pl|pm' => 'text/x-perl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1316
      'py' => 'text/x-python',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1317
      'etx' => 'text/x-setext',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1318
      'tcl|tk' => 'text/x-tcl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1319
      'tex|ltx|sty|cls' => 'text/x-tex',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1320
      'vcs' => 'text/x-vcalendar',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1321
      'vcf' => 'text/x-vcard',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1322
      '3gp' => 'video/3gpp',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1323
      'dl' => 'video/dl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1324
      'dif|dv' => 'video/dv',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1325
      'fli' => 'video/fli',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1326
      'gl' => 'video/gl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1327
      'mpeg|mpg|mpe' => 'video/mpeg',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1328
      'mp4' => 'video/mp4',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1329
      'ogv' => 'video/ogg',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1330
      'qt|mov' => 'video/quicktime',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1331
      'mxu' => 'video/vnd.mpegurl',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1332
      'lsf|lsx' => 'video/x-la-asf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1333
      'mng' => 'video/x-mng',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1334
      'asf|asx' => 'video/x-ms-asf',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1335
      'wm' => 'video/x-ms-wm',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1336
      'wmv' => 'video/x-ms-wmv',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1337
      'wmx' => 'video/x-ms-wmx',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1338
      'wvx' => 'video/x-ms-wvx',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1339
      'avi' => 'video/x-msvideo',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1340
      'movie' => 'video/x-sgi-movie',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1341
      'ice' => 'x-conference/x-cooltalk',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1342
      'sisx' => 'x-epoc/x-sisx-app',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1343
      'vrm|vrml|wrl' => 'x-world/x-vrml',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1344
      'xps' => 'application/vnd.ms-xpsdocument',
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1345
    ));
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1346
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1347
  foreach ($mapping as $ext_preg => $mime_match) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1348
    if (preg_match('!\.('. $ext_preg .')$!i', $filename)) {
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1349
      return $mime_match;
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1350
    }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1351
  }
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1352
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1353
  return 'application/octet-stream';
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1354
}
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1355
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1356
/**
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1357
 * @} End of "defgroup file".
0ff3ba646492 Create branch for drupal with first commit from local working copy
cavaliet@caf4f556-3d62-0410-8435-a86758001935
parents:
diff changeset
  1358
 */