You are here

Add new comment

Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

Drupal and safe mode

Drupal 6.x with small modification can also be used on servers with Safe Mode ON (safe_mode=1). Standard distribution of Drupal doesn't support Safe Mode out of the box. Joomla has support already build-in. Safe Mode ON can be bypassed with FTP directory functions.

Add following function to includes/file.inc:

function mkdir_ftp($directory) {
  $directory = "your_drupal_ftp_base_folder/" . $directory;
  $ftpConn = ftp_connect("ftp.your.domain");
  if(false == ftp_login($ftpConn, "your_login", "your_password")) {
    watchdog('file system',
        'The directory cannot be created, ftp_login() failed.',
        array(), WATCHDOG_ERROR);
    return FALSE;
  }
  if(false == ftp_mkdir($ftpConn, $directory)) {
    watchdog('file system',
        'The directory %directory cannot be created, ftp_mkdir() failed.',
        array('%directory' => $directory), WATCHDOG_ERROR);
    return FALSE;
  }
  if(false == ftp_chmod($ftpConn, 0777, $directory)) {
    watchdog('file system',
        'The directory %directory cannot be created, ftp_chmod() failed.',
        array('%directory' => $directory), WATCHDOG_ERROR);
    return FALSE;
  }
  ftp_close($ftpConn);
  
  return TRUE;
}

and call it instead of PHP mkdir() in the same file, in function file_check_directory():

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_ftp($directory)) {
      drupal_set_message(t('The directory %directory has been created.', array('%directory' => $directory)));
      @chmod($directory, 0775); // Necessary for non-webserver users.
    }
...

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.