You are here

public static function Utils::isFileNameSyntaxOk in N1ED - Visual editor as CKEditor plugin with Bootstrap support 7

2 calls to Utils::isFileNameSyntaxOk()
AFile::checkForErrors in vendor/edsdk/file-uploader-server-php/src/lib/file/AFile.php
FileUploaded::checkForErrors in vendor/edsdk/file-uploader-server-php/src/lib/file/FileUploaded.php

File

vendor/edsdk/file-uploader-server-php/src/lib/file/Utils.php, line 55

Class

Utils

Namespace

EdSDK\FileUploaderServer\lib\file

Code

public static function isFileNameSyntaxOk($name) {
  if (strlen($name) == 0 || $name == "." || strpos($name, "..") > -1) {
    return false;
  }
  for ($i = 0; $i < strlen(Utils::PROHIBITED_SYMBOLS); $i++) {
    if (strpos($name, substr(Utils::PROHIBITED_SYMBOLS, $i, 1)) !== false) {
      return false;
    }
  }
  if (strlen($name) > 260) {
    return false;
  }

  /*
           * TODO: fix this and uncomment
           * On Windows + IIS + PHP produces:
           * Warning:  preg_match(): Unknown modifier '\' in <b>...\vendor\edsdk\file-uploader-server-php\src\lib\file\Utils.php on line 83
           *
           * if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
              // https://stackoverflow.com/questions/6730009/validate-a-file-name-on-windows
              // https://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#file_and_directory_names
              $pattern =
                  "/" .
                  "^" .
                  "(?!" .
                  "  (?:" .
                  "    CON|PRN|AUX|NUL|" .
                  "    COM[1-9]|LPT[1-9]" .
                  "  )" .
                  "  (?:\\.[^.]*)?" .
                  "  $" .
                  ")" .
                  "[^<>:\"/\\\\|?*\\x00-\\x1F]*" .
                  "[^<>:\"/\\\\|?*\\x00-\\x1F\\ .]" .
                  "$/ui";
              if (!preg_match($pattern, $name))
                  return false;
          }*/
  return true;
}