You are here

function validate_s3 in Filebrowser 7.4

Same name and namespace in other branches
  1. 7.3 modules/s3_fb.module \validate_s3()
1 call to validate_s3()
filebrowser_validate in ./filebrowser.module
Implements hook_validate(). @inheritdoc

File

modules/s3_fb.module, line 3

Code

function validate_s3($path) {
  $client = awssdk_get_client('s3');
  $client
    ->registerStreamWrapper();
  if (!file_exists($path)) {

    //folder (object) does not exist so we wil create it
    $success = mkdir($path, 0777, TRUE);
    if (!$success) {
      form_set_error('file_path', t('The S3 directory %dir is not a valid directory and I\'m unable to help this.', array(
        '%dir' => $path,
      )));
    }
    else {
      drupal_set_message(t('The directory %dir has been created on S3.', array(
        '%dir' => $path,
      )));
    }
  }
  else {

    //Todo: check readability of S3 dir

    // php function is_readable() is avail in Amazon streamWrapper

    /*if (!is_readable($encoded_path)) {
        form_set_error('file_path', t('The directory %dir is not readable.', array(
        '%dir' => $path
        )));
      }*/
  }
}