You are here

function _pdfpreview_prepare_filesystem in PDFPreview 6

Same name and namespace in other branches
  1. 7.2 pdfpreview.module \_pdfpreview_prepare_filesystem()
  2. 7 pdfpreview.module \_pdfpreview_prepare_filesystem()

Prepares filesystem to store previews

1 call to _pdfpreview_prepare_filesystem()
pdfpreview_admin_settings_validate in ./pdfpreview.module
Implements hook_form_FORM_ID_validate()

File

./pdfpreview.module, line 199
This module creates a formatter for CCK filefields that shows a snapshot of the first page of pdf files as link to the file.

Code

function _pdfpreview_prepare_filesystem($output_dir) {
  $output_dir = _pdfpreview_realpath($output_dir);
  if (!file_exists($output_dir)) {
    if (!mkdir($output_dir)) {
      drupal_set_message(t('Error creating directory %dir', array(
        '%dir' => $output_dir,
      )), 'error');
      watchdog('pdfpreview', 'Error creating directory %dir', array(
        '%dir' => $output_dir,
      ), WATCHDOG_ERROR);
      return FALSE;
    }
    $message = t('The directory %dir has been created', array(
      '%dir' => $output_dir,
    ));
    watchdog('pdfpreview', 'The directory %dir has been created', array(
      '%dir' => $output_dir,
    ));
    drupal_set_message($message, 'status');
    return TRUE;
  }
  elseif (!is_dir($output_dir)) {
    $message = t('The path %dir is not a directory', array(
      '%dir' => $output_dir,
    ));
    watchdog('pdfpreview', 'The path %dir is not a directory', array(
      '%dir' => $output_dir,
    ), WATCHDOG_ERROR);
    drupal_set_message($message, 'error');
    return FALSE;
  }
  return TRUE;
}