Download & Extend

Warning mkdir() Safe mode restriction in effect.

Project:Administration
Version:4.7.x-1.x-dev
Component:Code
Category:support request
Priority:critical
Assigned:gbright
Status:active
Issue tags:mkdir, safe mode

Issue Summary

Hi I am getting this error from the drupal site admin > settings page for www.rainbowplanet.com.au

* warning: mkdir() [function.mkdir]: SAFE MODE Restriction in effect. The script whose uid is 33340 is not allowed to access /tmp owned by uid 0 in /home2/gavanbr/public_html/rainbowplanet/includes/file.inc on line 91.
* The directory /tmp does not exist.

What does this mean, how am I supposed to fix it?

I am a newbie and unsure what to do.

Can anybody help, it would be greatly appreaciated.

Regards

Gavan Bright

System specs
I am running Drupal 5.0
Operating system Linux
Service Status Click to View
Kernel version 2.6.9-42.0.8.ELsmp
Machine Type i686
Apache version 1.3.37 (Unix)
PERL version 5.8.7
PHP version 5.2.0
MySQL version 5.0.24-standard

Comments

#1

here is the code from the file.inc

<?php
>
function
file_check_directory(&$directory, $mode = 0, $form_item = NULL) {
 
$directory = rtrim($directory, '/\\');

 
// Check if directory exists.
 
if (!is_dir($directory)) {
    if ((
$mode & FILE_CREATE_DIRECTORY) && @mkdir($directory)) {
     
drupal_set_message(t('The directory %directory has been created.', array('%directory' => theme('placeholder', $directory))));
      @
chmod($directory, 0775); // Necessary for non-webserver users.
   
}
    else {
      if (
$form_item) {
       
form_set_error($form_item, t('The directory %directory does not exist.', array('%directory' => theme('placeholder', $directory))));
      }
      return
false;
    }
  }

 
// Check to see if the directory is writable.
 
if (!is_writable($directory)) {
    if ((
$mode & FILE_MODIFY_PERMISSIONS) && @chmod($directory, 0775)) {
     
drupal_set_message(t('The permissions of directory %directory have been changed to make it writable.', array('%directory' => theme('placeholder', $directory))));
    }
    else {
     
form_set_error($form_item, t('The directory %directory is not writable', array('%directory' => theme('placeholder', $directory))));
     
watchdog('file system', t('The directory %directory is not writable, because it does not have the correct permissions set.', array('%directory' => theme('placeholder', $directory))), WATCHDOG_ERROR);
      return
false;
    }
  }

  if ((
file_directory_path() == $directory || file_directory_temp() == $directory) && !is_file("$directory/.htaccess")) {
   
$htaccess_lines = "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks";
    if ((
$fp = fopen("$directory/.htaccess", 'w')) && fputs($fp, $htaccess_lines)) {
     
fclose($fp);
     
chmod($directory .'/.htaccess', 0664);
    }
    else {
     
$message = 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>", array('%directory' => theme('placeholder', $directory), '%htaccess' => '<br />'. str_replace("\n", '<br />', check_plain($htaccess_lines))));
     
form_set_error($form_item, $message);
     
watchdog('security', $message, WATCHDOG_ERROR);
    }
  }

  return
true;
}
?>

#2

You need to disable PHP's safe_mode directive (in php.ini or your httpd.conf or an htaccess file) in order to get access to /tmp (and a bunch of other places).

#3

I cannot turn SAFE MODE off.
And the error message 'The selected file %file could not be uploaded, because the destination %directory is not properly configured.' drove me crazy.

Luckily, I found solution on http://jan.baresovi.cz/dr/en/drupal-safe-mode

Following code added to file.inc worked for me:

<?php
//adding new function
function mkdir_ftp($directory) {

$ftpuser = "_your_ftp_user_";
$ftppass = "_your_ftp_password_";
$ftpdir = "_your_ftp_directory_";
$ftpservername = "_your_ftp_server_name_";

 
$directory = $ftpdir . $directory;
 
$ftpConn = ftp_connect($ftpservername);
  if(
false == ftp_login($ftpConn,$ftpuser , $ftppass)) {
   
watchdog('file system',
     
'The directory cannot be created, ftp_login() failed.',
      array(),
WATCHDOG_ERROR);
    return
FALSE;
  }
 
$list=split("/",$directory);
 
$directory="";$first=true;
  foreach(
$list as $ldir){
    if (
$first)
     
$directory.="".$ldir;
    else
     
$directory.="/".$ldir;
   
$first=false;
   
ftp_mkdir($ftpConn, $directory);
   
ftp_chmod($ftpConn, 0777, $directory);
  }
 
ftp_close($ftpConn);
  return
TRUE;
}

//...

function file_check_directory(&$directory, $mode = 0, $form_item = NULL) {
//...
    //if (($mode & FILE_CREATE_DIRECTORY) && @mkdir($directory)) { //does not work with SAFE MODE = on
   
if (($mode & FILE_CREATE_DIRECTORY) && @mkdir_ftp($directory)) { //does work with SAFE MODE = on
//...
}
?>