original_string: protected function checkUploadPostback()
      {
          if ($this->readOnly) {
              return;
          }
  
          $fileName = null;
          $quickMode = false;
  
          if (
              (!($uniqueId = Request::header('X-OCTOBER-FILEUPLOAD')) || $uniqueId != $this->getId()) &&
              (!$quickMode = post('X_OCTOBER_MEDIA_MANAGER_QUICK_UPLOAD'))
          ) {
              return;
          }
  
          try {
              if (!Input::hasFile('file_data')) {
                  throw new ApplicationException('File missing from request');
              }
  
              $uploadedFile = Input::file('file_data');
  
              $fileName = $uploadedFile->getClientOriginalName();
  
              /*
               * Convert uppcare case file extensions to lower case
               */
              $extension = strtolower($uploadedFile->getClientOriginalExtension());
              $fileName = File::name($fileName).'.'.$extension;
  
              /*
               * File name contains non-latin characters, attempt to slug the value
               */
              if (!$this->validateFileName($fileName)) {
                  $fileNameClean = $this->cleanFileName(File::name($fileName));
                  $fileName = $fileNameClean . '.' . $extension;
              }
  
              /*
               * Check for unsafe file extensions
               */
              if (!$this->validateFileType($fileName)) {
                  throw new ApplicationException(Lang::get('backend::lang.media.type_blocked'));
              }
  
              /*
               * See mime type handling in the asset manager
               */
              if (!$uploadedFile->isValid()) {
                  throw new ApplicationException($uploadedFile->getErrorMessage());
              }
  
              $path = $quickMode ? '/uploaded-files' : Input::get('path');
              $path = MediaLibrary::validatePath($path);
              $filePath = $path.'/'.$fileName;
  
              /*
               * getRealPath() can be empty for some environments (IIS)
               */
              $realPath = empty(trim($uploadedFile->getRealPath()))
                               ? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName()
                               : $uploadedFile->getRealPath();
  
              MediaLibrary::instance()->put(
                  $filePath,
                  File::get($realPath)
              );
  
              /**
               * @event media.file.upload
               * Called after a file is uploaded
               *
               * Example usage:
               *
               *     Event::listen('media.file.upload', function((\Backend\Widgets\MediaManager) $mediaWidget, (string) $path, (\Symfony\Component\HttpFoundation\File\UploadedFile) $uploadedFile) {
               *         \Log::info($path . " was upoaded.");
               *     });
               *
               * Or
               *
               *     $mediaWidget->bindEvent('file.upload', function ((string) $path, (\Symfony\Component\HttpFoundation\File\UploadedFile) $uploadedFile) {
               *         \Log::info($path . " was uploaded");
               *     });
               *
               */
              $this->fireSystemEvent('media.file.upload', [$filePath, $uploadedFile]);
  
              Response::json([
                  'link' => MediaLibrary::url($filePath),
                  'result' => 'success'
              ])->send();
          }
          catch (Exception $ex) {
              Response::json($ex->getMessage(), 400)->send();
          }
  
          exit;
      }
code: protected function checkUploadPostback()
      {
          if ($this->readOnly) {
              return;
          }
  
          $fileName = null;
          $quickMode = false;
  
          if (
              (!($uniqueId = Request::header('X-OCTOBER-FILEUPLOAD')) || $uniqueId != $this->getId()) &&
              (!$quickMode = post('X_OCTOBER_MEDIA_MANAGER_QUICK_UPLOAD'))
          ) {
              return;
          }
  
          try {
              if (!Input::hasFile('file_data')) {
                  throw new ApplicationException('File missing from request');
              }
  
              $uploadedFile = Input::file('file_data');
  
              $fileName = $uploadedFile->getClientOriginalName();
  
              /*
               * Convert uppcare case file extensions to lower case
               */
              $extension = strtolower($uploadedFile->getClientOriginalExtension());
              $fileName = File::name($fileName).'.'.$extension;
  
              /*
               * File name contains non-latin characters, attempt to slug the value
               */
              if (!$this->validateFileName($fileName)) {
                  $fileNameClean = $this->cleanFileName(File::name($fileName));
                  $fileName = $fileNameClean . '.' . $extension;
              }
  
              /*
               * Check for unsafe file extensions
               */
              if (!$this->validateFileType($fileName)) {
                  throw new ApplicationException(Lang::get('backend::lang.media.type_blocked'));
              }
  
              /*
               * See mime type handling in the asset manager
               */
              if (!$uploadedFile->isValid()) {
                  throw new ApplicationException($uploadedFile->getErrorMessage());
              }
  
              $path = $quickMode ? '/uploaded-files' : Input::get('path');
              $path = MediaLibrary::validatePath($path);
              $filePath = $path.'/'.$fileName;
  
              /*
               * getRealPath() can be empty for some environments (IIS)
               */
              $realPath = empty(trim($uploadedFile->getRealPath()))
                               ? $uploadedFile->getPath() . DIRECTORY_SEPARATOR . $uploadedFile->getFileName()
                               : $uploadedFile->getRealPath();
  
              MediaLibrary::instance()->put(
                  $filePath,
                  File::get($realPath)
              );
  
              /**
               * @event media.file.upload
               * Called after a file is uploaded
               *
               * Example usage:
               *
               *     Event::listen('media.file.upload', function((\Backend\Widgets\MediaManager) $mediaWidget, (string) $path, (\Symfony\Component\HttpFoundation\File\UploadedFile) $uploadedFile) {
               *         \Log::info($path . " was upoaded.");
               *     });
               *
               * Or
               *
               *     $mediaWidget->bindEvent('file.upload', function ((string) $path, (\Symfony\Component\HttpFoundation\File\UploadedFile) $uploadedFile) {
               *         \Log::info($path . " was uploaded");
               *     });
               *
               */
              $this->fireSystemEvent('media.file.upload', [$filePath, $uploadedFile]);
  
              Response::json([
                  'link' => MediaLibrary::url($filePath),
                  'result' => 'success'
              ])->send();
          }
          catch (Exception $ex) {
              Response::json($ex->getMessage(), 400)->send();
          }
  
          exit;
      }
code_tokens: protected function checkUploadPostback ( ) { if ( $ this -> readOnly ) { return ; } $ fileName = null ; $ quickMode = false ; if ( ( ! ( $ uniqueId = Request :: header ( 'X-OCTOBER-FILEUPLOAD' ) ) || $ uniqueId != $ this -> getId ( ) ) && ( ! $ quickMode = post ( 'X_OCTOBER_MEDIA_MANAGER_QUICK_UPLOAD' ) ) ) { return ; } try { if ( ! Input :: hasFile ( 'file_data' ) ) { throw new ApplicationException ( 'File missing from request' ) ; } $ uploadedFile = Input :: file ( 'file_data' ) ; $ fileName = $ uploadedFile -> getClientOriginalName ( ) ; /*
               * Convert uppcare case file extensions to lower case
               */ $ extension = strtolower ( $ uploadedFile -> getClientOriginalExtension ( ) ) ; $ fileName = File :: name ( $ fileName ) . '.' . $ extension ; /*
               * File name contains non-latin characters, attempt to slug the value
               */ if ( ! $ this -> validateFileName ( $ fileName ) ) { $ fileNameClean = $ this -> cleanFileName ( File :: name ( $ fileName ) ) ; $ fileName = $ fileNameClean . '.' . $ extension ; } /*
               * Check for unsafe file extensions
               */ if ( ! $ this -> validateFileType ( $ fileName ) ) { throw new ApplicationException ( Lang :: get ( 'backend::lang.media.type_blocked' ) ) ; } /*
               * See mime type handling in the asset manager
               */ if ( ! $ uploadedFile -> isValid ( ) ) { throw new ApplicationException ( $ uploadedFile -> getErrorMessage ( ) ) ; } $ path = $ quickMode ? '/uploaded-files' : Input :: get ( 'path' ) ; $ path = MediaLibrary :: validatePath ( $ path ) ; $ filePath = $ path . '/' . $ fileName ; /*
               * getRealPath() can be empty for some environments (IIS)
               */ $ realPath = empty ( trim ( $ uploadedFile -> getRealPath ( ) ) ) ? $ uploadedFile -> getPath ( ) . DIRECTORY_SEPARATOR . $ uploadedFile -> getFileName ( ) : $ uploadedFile -> getRealPath ( ) ; MediaLibrary :: instance ( ) -> put ( $ filePath , File :: get ( $ realPath ) ) ; /**
               * @event media.file.upload
               * Called after a file is uploaded
               *
               * Example usage:
               *
               *     Event::listen('media.file.upload', function((\Backend\Widgets\MediaManager) $mediaWidget, (string) $path, (\Symfony\Component\HttpFoundation\File\UploadedFile) $uploadedFile) {
               *         \Log::info($path . " was upoaded.");
               *     });
               *
               * Or
               *
               *     $mediaWidget->bindEvent('file.upload', function ((string) $path, (\Symfony\Component\HttpFoundation\File\UploadedFile) $uploadedFile) {
               *         \Log::info($path . " was uploaded");
               *     });
               *
               */ $ this -> fireSystemEvent ( 'media.file.upload' , [ $ filePath , $ uploadedFile ] ) ; Response :: json ( [ 'link' => MediaLibrary :: url ( $ filePath ) , 'result' => 'success' ] ) -> send ( ) ; } catch ( Exception $ ex ) { Response :: json ( $ ex -> getMessage ( ) , 400 ) -> send ( ) ; } exit ; }
docstring: Detect the upload post flag
  @return void
docstring_tokens: Detect the upload post flag