Exemple #1
0
 protected function checkUploadPostback()
 {
     $fileName = null;
     if (!($uniqueId = post('X_OCTOBER_FILEUPLOAD')) || $uniqueId != $this->getId()) {
         return;
     }
     try {
         if (!Input::hasFile('file_data')) {
             return;
         }
         $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)) {
             $fileNameSlug = Str::slug(File::name($fileName), '-');
             $fileName = $fileNameSlug . '.' . $extension;
         }
         // See mime type handling in the asset manager
         if (!$uploadedFile->isValid()) {
             throw new ApplicationException($uploadedFile->getErrorMessage());
         }
         $path = Input::get('path');
         $path = MediaLibrary::validatePath($path);
         MediaLibrary::instance()->put($path . '/' . $fileName, File::get($uploadedFile->getRealPath()));
         die('success');
     } catch (Exception $ex) {
         Response::make($ex->getMessage(), 406)->send();
         die;
     }
 }
Exemple #2
0
 protected function checkUploadPostback()
 {
     $fileName = null;
     if (!($uniqueId = post('X_OCTOBER_FILEUPLOAD')) || $uniqueId != $this->getId()) {
         return;
     }
     try {
         if (!Input::hasFile('file_data')) {
             return;
         }
         $uploadedFile = Input::file('file_data');
         $fileName = $uploadedFile->getClientOriginalName();
         // See mime type handling in the asset manager
         if (!$uploadedFile->isValid()) {
             throw new ApplicationException($uploadedFile->getErrorMessage());
         }
         $path = Input::get('path');
         $path = MediaLibrary::validatePath($path);
         MediaLibrary::instance()->put($path . '/' . $fileName, File::get($uploadedFile->getRealPath()));
         die('success');
     } catch (Exception $ex) {
         Response::make($ex->getMessage(), 406)->send();
         die;
     }
 }
Exemple #3
0
 protected function checkUploadPostback()
 {
     $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('cms::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;
         MediaLibrary::instance()->put($filePath, File::get($uploadedFile->getRealPath()));
         Response::json(['link' => MediaLibrary::url($filePath), 'result' => 'success'])->send();
     } catch (Exception $ex) {
         Response::json($ex->getMessage(), 400)->send();
     }
     exit;
 }
 /**
  * @dataProvider validPathsProvider
  */
 public function testValidPathsOnValidatePath($path)
 {
     MediaLibrary::validatePath($path);
 }
 public function onResizeImage()
 {
     $cropSessionKey = Input::get('cropSessionKey');
     if (!preg_match('/^[0-9a-z]+$/', $cropSessionKey)) {
         throw new ApplicationException('Invalid input data');
     }
     $width = trim(Input::get('width'));
     if (!strlen($width) || !ctype_digit($width)) {
         throw new ApplicationException('Invalid input data');
     }
     $height = trim(Input::get('height'));
     if (!strlen($height) || !ctype_digit($height)) {
         throw new ApplicationException('Invalid input data');
     }
     $path = Input::get('path');
     $path = MediaLibrary::validatePath($path);
     $params = array('width' => $width, 'height' => $height);
     return $this->getCropEditImageUrlAndSize($path, $cropSessionKey, $params);
 }