- Patch #26249 by Morbus: improved handling of temporary files/directory.
If your module uses variable_get('file_directory_temp', ...) or variable_get('file_directory_path', ...) please update it to use the new API. A list of affected modules is available at http://drupal.org/node/26249#comment-54194.4.7.x
parent
7dd24bec5c
commit
64a617c208
|
@ -27,12 +27,12 @@ define('FILE_EXISTS_ERROR', 2);
|
||||||
* @return URL pointing to the file
|
* @return URL pointing to the file
|
||||||
*/
|
*/
|
||||||
function file_create_url($path) {
|
function file_create_url($path) {
|
||||||
if (strpos($path, variable_get('file_directory_path', 'files')) !== false) {
|
if (strpos($path, file_directory_path()) !== false) {
|
||||||
$path = trim(substr($path, strlen(variable_get('file_directory_path', 'files'))), '\\/');
|
$path = trim(substr($path, strlen(file_directory_path())), '\\/');
|
||||||
}
|
}
|
||||||
switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
|
switch (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC)) {
|
||||||
case FILE_DOWNLOADS_PUBLIC:
|
case FILE_DOWNLOADS_PUBLIC:
|
||||||
return $GLOBALS['base_url'] .'/'. variable_get('file_directory_path', 'files') .'/'. str_replace('\\', '/', $path);
|
return $GLOBALS['base_url'] .'/'. file_directory_path() .'/'. str_replace('\\', '/', $path);
|
||||||
case FILE_DOWNLOADS_PRIVATE:
|
case FILE_DOWNLOADS_PRIVATE:
|
||||||
return url('system/files', 'file='. $path, NULL, TRUE);
|
return url('system/files', 'file='. $path, NULL, TRUE);
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ function file_create_url($path) {
|
||||||
* Returns FALSE if the path is invalid (i.e. outside the configured 'files'-directory).
|
* Returns FALSE if the path is invalid (i.e. outside the configured 'files'-directory).
|
||||||
*/
|
*/
|
||||||
function file_create_path($dest = 0) {
|
function file_create_path($dest = 0) {
|
||||||
$file_path = variable_get('file_directory_path', 'files');
|
$file_path = file_directory_path();
|
||||||
if (!$dest) {
|
if (!$dest) {
|
||||||
return $file_path;
|
return $file_path;
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,10 @@ function file_create_path($dest = 0) {
|
||||||
return $dest;
|
return $dest;
|
||||||
}
|
}
|
||||||
// check if the destination is instead inside the Drupal temporary files directory.
|
// check if the destination is instead inside the Drupal temporary files directory.
|
||||||
else if (file_check_location($dest, variable_get('file_directory_temp', ini_get('upload_tmp_dir')))) {
|
else if (file_check_location($dest, file_directory_temp())) {
|
||||||
return $dest;
|
return $dest;
|
||||||
}
|
}
|
||||||
// Not found, try again with prefixed dirctory path.
|
// Not found, try again with prefixed directory path.
|
||||||
else if (file_check_location($file_path . '/' . $dest, $file_path)) {
|
else if (file_check_location($file_path . '/' . $dest, $file_path)) {
|
||||||
return $file_path . '/' . $dest;
|
return $file_path . '/' . $dest;
|
||||||
}
|
}
|
||||||
|
@ -367,7 +367,7 @@ function file_save_upload($source, $dest = 0, $replace = FILE_EXISTS_RENAME) {
|
||||||
// Make sure $source exists in $_FILES.
|
// Make sure $source exists in $_FILES.
|
||||||
if ($file = file_check_upload($source)) {
|
if ($file = file_check_upload($source)) {
|
||||||
if (!$dest) {
|
if (!$dest) {
|
||||||
$dest = variable_get('file_directory_temp', ini_get('upload_tmp_dir'));
|
$dest = file_directory_temp();
|
||||||
$temporary = 1;
|
$temporary = 1;
|
||||||
if (is_file($file->filepath)) {
|
if (is_file($file->filepath)) {
|
||||||
// If this file was uploaded by this user before replace the temporary copy.
|
// If this file was uploaded by this user before replace the temporary copy.
|
||||||
|
@ -425,7 +425,7 @@ function file_save_data($data, $dest, $replace = FILE_EXISTS_RENAME) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$temp = variable_get('file_directory_temp', ini_get('upload_tmp_dir'));
|
$temp = file_directory_temp();
|
||||||
$file = tempnam($temp, 'file');
|
$file = tempnam($temp, 'file');
|
||||||
if (!$fp = fopen($file, 'wb')) {
|
if (!$fp = fopen($file, 'wb')) {
|
||||||
drupal_set_message(t('The file could not be created.'), 'error');
|
drupal_set_message(t('The file could not be created.'), 'error');
|
||||||
|
@ -551,4 +551,50 @@ function file_scan_directory($dir, $mask, $nomask = array('.', '..', 'CVS'), $ca
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the default temporary directory.
|
||||||
|
*/
|
||||||
|
function file_directory_temp() {
|
||||||
|
$temporary_directory = variable_get('file_directory_temp', NULL);
|
||||||
|
|
||||||
|
if (is_null($temporary_directory)) {
|
||||||
|
$directories = array();
|
||||||
|
|
||||||
|
// Has PHP been set with an upload_tmp_dir?
|
||||||
|
if (ini_get('upload_tmp_dir')) {
|
||||||
|
$directories[] = ini_get('upload_tmp_dir');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Operating system specific dirs.
|
||||||
|
if (substr(PHP_OS, 0, 3) == 'WIN') {
|
||||||
|
$directories[] = 'c:\\windows\\temp';
|
||||||
|
$directories[] = 'c:\\winnt\\temp';
|
||||||
|
$path_delimiter = '\\';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$directories[] = '/tmp';
|
||||||
|
$path_delimiter = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($directories as $directory) {
|
||||||
|
if (!$temporary_directory && is_dir($directory)) {
|
||||||
|
$temporary_directory = $directory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if a directory has been found, use it, otherwise default to 'files/tmp' or 'files\\tmp';
|
||||||
|
$temporary_directory = $temporary_directory ? $temporary_directory : file_directory_path() . $path_delimiter . 'tmp';
|
||||||
|
variable_set('file_directory_temp', $temporary_directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $temporary_directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine the default 'files' directory.
|
||||||
|
*/
|
||||||
|
function file_directory_path() {
|
||||||
|
return variable_get('file_directory_path', 'files');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,7 @@ function system_view_general() {
|
||||||
// File system:
|
// File system:
|
||||||
$form['files'] = array('#type' => 'fieldset', '#title' => t('File system settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
|
$form['files'] = array('#type' => 'fieldset', '#title' => t('File system settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
|
||||||
|
|
||||||
$directory_path = variable_get('file_directory_path', 'files');
|
$directory_path = file_directory_path();
|
||||||
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
|
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
|
||||||
|
|
||||||
$form['files']['file_directory_path'] = array(
|
$form['files']['file_directory_path'] = array(
|
||||||
|
@ -325,7 +325,7 @@ function system_view_general() {
|
||||||
'#description' => t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.')
|
'#description' => t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.')
|
||||||
);
|
);
|
||||||
|
|
||||||
$directory_temp = variable_get('file_directory_temp', ini_get('upload_tmp_dir'));
|
$directory_temp = file_directory_temp();
|
||||||
file_check_directory($directory_temp, FILE_CREATE_DIRECTORY, 'file_directory_temp');
|
file_check_directory($directory_temp, FILE_CREATE_DIRECTORY, 'file_directory_temp');
|
||||||
|
|
||||||
$form['files']['file_directory_temp'] = array(
|
$form['files']['file_directory_temp'] = array(
|
||||||
|
@ -961,7 +961,7 @@ function system_site_settings($module = NULL) {
|
||||||
* Menu callback; display theme configuration for entire site and individual themes.
|
* Menu callback; display theme configuration for entire site and individual themes.
|
||||||
*/
|
*/
|
||||||
function system_theme_settings($key = '') {
|
function system_theme_settings($key = '') {
|
||||||
$directory_path = variable_get('file_directory_path', 'files');
|
$directory_path = file_directory_path();
|
||||||
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
|
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
|
||||||
|
|
||||||
// Default settings are defined in theme_get_settings() in includes/theme.inc
|
// Default settings are defined in theme_get_settings() in includes/theme.inc
|
||||||
|
|
|
@ -317,7 +317,7 @@ function system_view_general() {
|
||||||
// File system:
|
// File system:
|
||||||
$form['files'] = array('#type' => 'fieldset', '#title' => t('File system settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
|
$form['files'] = array('#type' => 'fieldset', '#title' => t('File system settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
|
||||||
|
|
||||||
$directory_path = variable_get('file_directory_path', 'files');
|
$directory_path = file_directory_path();
|
||||||
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
|
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
|
||||||
|
|
||||||
$form['files']['file_directory_path'] = array(
|
$form['files']['file_directory_path'] = array(
|
||||||
|
@ -325,7 +325,7 @@ function system_view_general() {
|
||||||
'#description' => t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.')
|
'#description' => t('A file system path where the files will be stored. This directory has to exist and be writable by Drupal. If the download method is set to public this directory has to be relative to Drupal installation directory, and be accessible over the web. When download method is set to private this directory should not be accessible over the web. Changing this location after the site has been in use will cause problems so only change this setting on an existing site if you know what you are doing.')
|
||||||
);
|
);
|
||||||
|
|
||||||
$directory_temp = variable_get('file_directory_temp', ini_get('upload_tmp_dir'));
|
$directory_temp = file_directory_temp();
|
||||||
file_check_directory($directory_temp, FILE_CREATE_DIRECTORY, 'file_directory_temp');
|
file_check_directory($directory_temp, FILE_CREATE_DIRECTORY, 'file_directory_temp');
|
||||||
|
|
||||||
$form['files']['file_directory_temp'] = array(
|
$form['files']['file_directory_temp'] = array(
|
||||||
|
@ -961,7 +961,7 @@ function system_site_settings($module = NULL) {
|
||||||
* Menu callback; display theme configuration for entire site and individual themes.
|
* Menu callback; display theme configuration for entire site and individual themes.
|
||||||
*/
|
*/
|
||||||
function system_theme_settings($key = '') {
|
function system_theme_settings($key = '') {
|
||||||
$directory_path = variable_get('file_directory_path', 'files');
|
$directory_path = file_directory_path();
|
||||||
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
|
file_check_directory($directory_path, FILE_CREATE_DIRECTORY, 'file_directory_path');
|
||||||
|
|
||||||
// Default settings are defined in theme_get_settings() in includes/theme.inc
|
// Default settings are defined in theme_get_settings() in includes/theme.inc
|
||||||
|
|
|
@ -1777,7 +1777,7 @@ function user_configure() {
|
||||||
|
|
||||||
$form['pictures'] = array('#type' => 'fieldset', '#title' => t('Pictures'));
|
$form['pictures'] = array('#type' => 'fieldset', '#title' => t('Pictures'));
|
||||||
$form['pictures']['user_pictures'] = array('#type' => 'radios', '#title' => t('Picture support'), '#default_value' => variable_get('user_pictures', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Enable picture support.'));
|
$form['pictures']['user_pictures'] = array('#type' => 'radios', '#title' => t('Picture support'), '#default_value' => variable_get('user_pictures', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Enable picture support.'));
|
||||||
$form['pictures']['user_picture_path'] = array('#type' => 'textfield', '#title' => t('Picture image path'), '#default_value' => variable_get('user_picture_path', 'pictures'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => variable_get('file_directory_path', 'files') .'/')));
|
$form['pictures']['user_picture_path'] = array('#type' => 'textfield', '#title' => t('Picture image path'), '#default_value' => variable_get('user_picture_path', 'pictures'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => file_directory_path() .'/')));
|
||||||
$form['pictures']['user_picture_default'] = array('#type' => 'textfield', '#title' => t('Default picture'), '#default_value' => variable_get('user_picture_default', ''), '#size' => 30, '#maxlength' => 255, '#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
|
$form['pictures']['user_picture_default'] = array('#type' => 'textfield', '#title' => t('Default picture'), '#default_value' => variable_get('user_picture_default', ''), '#size' => 30, '#maxlength' => 255, '#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
|
||||||
$form['pictures']['user_picture_dimensions'] = array('#type' => 'textfield', '#title' => t('Picture maximum dimensions'), '#default_value' => variable_get('user_picture_dimensions', '85x85'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum dimensions for pictures.'));
|
$form['pictures']['user_picture_dimensions'] = array('#type' => 'textfield', '#title' => t('Picture maximum dimensions'), '#default_value' => variable_get('user_picture_dimensions', '85x85'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum dimensions for pictures.'));
|
||||||
$form['pictures']['user_picture_file_size'] = array('#type' => 'textfield', '#title' => t('Picture maximum file size'), '#default_value' => variable_get('user_picture_file_size', '30'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum file size for pictures, in kB.'));
|
$form['pictures']['user_picture_file_size'] = array('#type' => 'textfield', '#title' => t('Picture maximum file size'), '#default_value' => variable_get('user_picture_file_size', '30'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum file size for pictures, in kB.'));
|
||||||
|
|
|
@ -1777,7 +1777,7 @@ function user_configure() {
|
||||||
|
|
||||||
$form['pictures'] = array('#type' => 'fieldset', '#title' => t('Pictures'));
|
$form['pictures'] = array('#type' => 'fieldset', '#title' => t('Pictures'));
|
||||||
$form['pictures']['user_pictures'] = array('#type' => 'radios', '#title' => t('Picture support'), '#default_value' => variable_get('user_pictures', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Enable picture support.'));
|
$form['pictures']['user_pictures'] = array('#type' => 'radios', '#title' => t('Picture support'), '#default_value' => variable_get('user_pictures', 0), '#options' => array(t('Disabled'), t('Enabled')), '#description' => t('Enable picture support.'));
|
||||||
$form['pictures']['user_picture_path'] = array('#type' => 'textfield', '#title' => t('Picture image path'), '#default_value' => variable_get('user_picture_path', 'pictures'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => variable_get('file_directory_path', 'files') .'/')));
|
$form['pictures']['user_picture_path'] = array('#type' => 'textfield', '#title' => t('Picture image path'), '#default_value' => variable_get('user_picture_path', 'pictures'), '#size' => 30, '#maxlength' => 255, '#description' => t('Subdirectory in the directory "%dir" where pictures will be stored.', array('%dir' => file_directory_path() .'/')));
|
||||||
$form['pictures']['user_picture_default'] = array('#type' => 'textfield', '#title' => t('Default picture'), '#default_value' => variable_get('user_picture_default', ''), '#size' => 30, '#maxlength' => 255, '#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
|
$form['pictures']['user_picture_default'] = array('#type' => 'textfield', '#title' => t('Default picture'), '#default_value' => variable_get('user_picture_default', ''), '#size' => 30, '#maxlength' => 255, '#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'));
|
||||||
$form['pictures']['user_picture_dimensions'] = array('#type' => 'textfield', '#title' => t('Picture maximum dimensions'), '#default_value' => variable_get('user_picture_dimensions', '85x85'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum dimensions for pictures.'));
|
$form['pictures']['user_picture_dimensions'] = array('#type' => 'textfield', '#title' => t('Picture maximum dimensions'), '#default_value' => variable_get('user_picture_dimensions', '85x85'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum dimensions for pictures.'));
|
||||||
$form['pictures']['user_picture_file_size'] = array('#type' => 'textfield', '#title' => t('Picture maximum file size'), '#default_value' => variable_get('user_picture_file_size', '30'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum file size for pictures, in kB.'));
|
$form['pictures']['user_picture_file_size'] = array('#type' => 'textfield', '#title' => t('Picture maximum file size'), '#default_value' => variable_get('user_picture_file_size', '30'), '#size' => 15, '#maxlength' => 10, '#description' => t('Maximum file size for pictures, in kB.'));
|
||||||
|
|
Loading…
Reference in New Issue