isOk() публичный Метод

Is there any error?
public isOk ( ) : boolean
Результат boolean
Пример #1
0
 /**
  * @param FileUpload $fileUpload
  */
 public function upload(FileUpload $fileUpload, $path)
 {
     if (!$fileUpload->isOk()) {
         throw new ImageUploadedException('Chyba při nahrávání obrázku');
     }
     $fileUpload->move($path);
 }
Пример #2
0
 /**
  * @param FileUpload|NULL $file
  * @param string $folder
  *
  * @return array|bool
  */
 protected function saveImage(FileUpload $file = NULL, $folder = '')
 {
     if ($this->mainManager instanceof MagicManager) {
         $folder = $this->mainManager->getImageFolder();
     } else {
         if ($folder == '') {
             $folder = 'misc';
         }
     }
     // Main image
     $image = NULL;
     if (isset($file) && $file->isOk()) {
         // Save ...
         $year = date('Y');
         $month = date('m');
         $namespace = "{$folder}/{$year}/{$month}";
         $this->imageStorage->setNamespace($namespace);
         $image = $this->imageStorage->save($file->getContents(), $file->getName());
         $filename = pathinfo($image->getFile(), PATHINFO_BASENAME);
         // Prepare thumbnail
         $this->imgPipe->setNamespace($namespace);
         $this->imgPipe->request($filename, '200x200', 'exact');
         $this->imgPipe->setNamespace($namespace);
         $this->imgPipe->request($filename, '100x100', 'exact');
         $data = ['namespace' => $namespace, 'filename' => $filename];
         return $data;
     } else {
         return FALSE;
     }
 }
Пример #3
0
 /**
  * @param FileUpload $file
  * @return Image
  * @throws \Nette\InvalidArgumentException
  */
 public function upload(FileUpload $file)
 {
     if (!$file->isOk() || !$file->isImage()) {
         throw new Nette\InvalidArgumentException();
     }
     do {
         $name = Random::generate() . '.' . $file->getSanitizedName();
     } while (file_exists($path = $this->imagesDir . "/" . $this->namespace . $this->originalPrefix . "/" . $name));
     $file->move($path);
     $this->onUploadImage($path, $this->namespace);
     $this->namespace = NULL;
     return new Image($path);
 }
Пример #4
0
 /**
  * @param FileUpload $fileUpload
  * @param string $namespace
  * @param callable $callback
  * @return string Absolute name
  */
 public function saveUpload(FileUpload $fileUpload, $namespace = NULL, callable $callback = NULL)
 {
     if (!$fileUpload->isOk() || !$fileUpload->isImage()) {
         return NULL;
     }
     $image = $this->createImage();
     $image->setNamespace($namespace);
     $image->setName($fileUpload->getSanitizedName());
     if ($callback) {
         $callback($image);
     }
     $image->saveUpload($fileUpload);
     return (string) $image;
 }
Пример #5
0
 public function savaOriginImage($namespace, FileUpload $file)
 {
     if (!$file->isOk() || !$file->isImage()) {
         throw new ImageStorageException("invalid image");
     }
     $i = 1;
     $name = $file->getSanitizedName();
     $path = $this->getPath($namespace, $name);
     while (file_exists($path)) {
         $name = $i . '-' . $file->getSanitizedName();
         $path = $this->getPath($namespace, $name);
         $i++;
     }
     $file->move($path);
     return $name;
 }
Пример #6
0
 /**
  * @param FileUpload $file
  */
 public function process(FileUpload $file)
 {
     // check
     if ($file->isImage() && $file->isOk()) {
         // lets rock
         foreach ($this->thumbs as $thumb) {
             $thumb->setOriginalName($file->sanitizedName);
             $this->onProcess($file, $thumb);
         }
         // Fire complete handlers..
         $this->onComplete($this);
     }
     if (count($this->errors) > 0) {
         // Fire error handlers..
         $this->onError($this, $this->errors);
     } else {
         // Fire sucess handlers..
         $this->onSuccess($this, $this->images);
     }
 }
Пример #7
0
 /**
  * Prida soubor do db
  * @param \Nette\Http\FileUpload $file
  * @return type 
  */
 public function addFile($file, $userId = NULL)
 {
     if ($file instanceof \Nette\Http\FileUpload) {
         if (!$file->isOk()) {
             return false;
         }
         $folder = $this->getFolder('', FALSE);
         if (!$folder) {
             throw new VirtualDriveException('Current folder not found', 3011);
         }
         $name = $this->model->addFile($file, $folder['folder_id'], 0, $userId);
         /*if(!file_exists($this->getFullPath(TRUE).'/images')){
               @mkdir($this->getFullPath(TRUE).'/images', 0777, TRUE);
           }*/
         $filename = $this->uploadFile($file, $name);
         return $this->_getIdFromFileName($filename);
     } else {
         throw new VirtualDriveException('Wrong file type!', 3012);
     }
 }
Пример #8
0
 /**
  * @param  FileUpload
  * @param  string|NULL
  * @param  array|string|NULL
  * @return string  filepath (namespace/file.ext)
  * @throws ImageStorageException
  */
 public function upload(FileUpload $image, $namespace = NULL, $mimeTypes = NULL)
 {
     if (!$image->isOk()) {
         throw new ImageStorageException('File is broken');
     }
     if (!$image->isImage()) {
         $contentType = $image->getContentType();
         $isValid = FALSE;
         if (isset($mimeTypes)) {
             $mimeTypes = is_array($mimeTypes) ? $mimeTypes : explode(',', $mimeTypes);
             $isValid = in_array($contentType, $mimeTypes, TRUE);
         }
         if (!$isValid) {
             throw new ImageStorageException('File must be image, ' . $contentType . ' given');
         }
     }
     $sanitizedName = $image->getSanitizedName();
     $ext = pathinfo($sanitizedName, PATHINFO_EXTENSION);
     $sanitizedName = pathinfo($sanitizedName, PATHINFO_FILENAME) . '.' . Strings::lower($ext);
     $file = $this->generateFilePath($sanitizedName, $namespace);
     $path = $this->getPath($file);
     $image->move($path);
     return $file;
 }
Пример #9
0
 /**
  * @param \Nette\Http\FileUpload $file
  * @param string $filename
  * @throws IOException
  * @return string
  */
 public function writeUploaded(Nette\Http\FileUpload $file, $filename = NULL)
 {
     if (!$file->isOk()) {
         throw new IOException("Cannot save corrupted file.");
     }
     do {
         $name = Nette\Utils\Strings::random(10) . '.' . ($filename ?: $file->getSanitizedName());
     } while (file_exists($path = $this->dir . DIRECTORY_SEPARATOR . $name));
     $file->move($path);
     return basename($path);
 }
Пример #10
0
 /**
  * Save uploaded file
  *
  * @param FileUpload $file
  * @param string $path
  * @return string
  */
 public static function save(FileUpload $file, $path)
 {
     if (!$file->isOk()) {
         return FALSE;
     }
     $pathName = self::prepareToSaveFile($file->getSanitizedName(), $path);
     $file->move($pathName);
     return basename($pathName);
 }
 /**
  * Checks file if is ok and can be processed
  * @param \Nette\Http\FileUpload $file
  * @return bool
  */
 public static function validateFile(\Nette\Http\FileUpload $file)
 {
     return $file->isOk();
 }
Пример #12
0
 /**
  * edit user
  * todo: use it or edit()?
  *
  * @param $id
  * @param $email string
  * @param $username string
  * @param $password string
  * @param $role string
  * @param $name string
  * @param Nette\Http\FileUpload $avatar
  * @return bool
  * @throws DuplicateEntryException
  */
 public function editUser($id, $email, $username, $password, $role, $name, Nette\Http\FileUpload $avatar = NULL)
 {
     $data = array('email' => $email, 'username' => $username, 'role' => $role, 'name' => $name);
     if ($this->useFiles && $avatar && $avatar->isOk()) {
         $data['avatar'] = $this->saveImage($avatar);
     }
     if ($password !== '') {
         $data['password'] = Passwords::hash($password);
     }
     try {
         $this->get($id)->update($data);
     } catch (\PDOException $e) {
         if ($e->getCode() == '23000') {
             throw new DuplicateEntryException();
         } else {
             throw $e;
         }
     }
     return TRUE;
 }
 /**
  * Checks file if is ok and can be processed
  * @param FileUpload $file
  * @return bool
  */
 public static function validateFile(FileUpload $file)
 {
     return $file->isOk();
 }
Пример #14
0
 /**
  * @param Nette\Http\FileUpload $file
  * @return string|NULL
  */
 public function saveUpload(Nette\Http\FileUpload $file)
 {
     if ($file->isOk()) {
         $fileName = $this->getFileNameForSave($file->getName());
         $origPath = $this->getOrigPath($fileName);
         $file->move($origPath);
         if ($this->createImage($origPath, $this->getCompressionPath($fileName))) {
             return basename($origPath);
         }
     }
     return NULL;
 }
Пример #15
0
 /**
  *
  * @param \Nette\Http\FileUpload $file
  * @param string $path
  * @return TRUE
  */
 public static function save(\Nette\Http\FileUpload $file, $path)
 {
     if (!$file->isOk()) {
         return FALSE;
     }
     self::mkDir($path);
     $path = realpath($path) . DIRECTORY_SEPARATOR;
     $name = $file->sanitizedName;
     do {
         $pathName = $path . $name;
         $name = \Nette\Utils\Strings::random(5) . $name;
     } while (file_exists($pathName));
     $file->move($pathName);
     return basename($pathName);
 }
Пример #16
0
 /**
  * File upload handler. Saves file into upload folder and saves origin name to cache.
  *
  * @return void
  */
 public function handlePluploadFile()
 {
     // $this->getParameter('token') is not working
     if (!array_key_exists($this->getParameterId('token'), $_GET)) {
         $this->presenter->sendJson(array('status' => 'error', 'message' => 'Token is missing.'));
     }
     $token = $_GET[$this->getParameterId('token')];
     if (empty($_FILES)) {
         $this->presenter->sendJson(array('File is missing.'));
     }
     $file = new Nette\Http\FileUpload(end($_FILES));
     if (!$file->isOk()) {
         $this->presenter->sendJson(array('status' => 'error', 'message' => $this->getError($file->getError())));
     }
     $tempName = uniqid('np-') . '.' . pathinfo($file->getName(), PATHINFO_EXTENSION);
     $file->move($this->form->getUploadDir() . '/' . $tempName);
     $files = $this->form->cache->load($token, function () {
         return array();
     });
     $files[] = $file;
     $this->form->cache->save($token, $files);
     $this->presenter->sendJson(array('status' => 'success'));
 }