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

Returns the error code. {@link http://php.net/manual/en/features.file-upload.errors.php}
public getError ( ) : integer
Результат integer
Пример #1
0
 /**
  * @param string $namespace
  * @param FileUpload $fileUpload
  * @return SplFileInfo
  * @throws UploadErrorException
  */
 public function singleFileToDir($namespace, FileUpload $fileUpload)
 {
     if ($error = $fileUpload->getError()) {
         throw new UploadErrorException($error);
     }
     /** @var IManager $manager */
     $manager = $this->managerProvider->get($fileUpload);
     $relativePath = Utils::normalizePath($manager->getStorage()->getRelativePath() . '/' . $namespace);
     $this->onFileBegin($fileUpload, $relativePath);
     $uploadedFile = $manager->upload($namespace, $fileUpload);
     $this->onFileComplete($uploadedFile, $fileUpload, $relativePath);
     return $uploadedFile;
 }
Пример #2
0
 /**
  * Return file upload error message.
  * @param  FileUpload $file
  * @param  UI\Presenter $presenter
  * @return bool
  */
 public static function hasFileError(FileUpload $file, UI\Presenter &$presenter, $noFileError = TRUE)
 {
     switch ($file->getError()) {
         case UPLOAD_ERR_INI_SIZE:
             $presenter->flashMessage('The uploaded file exceeds the upload_max_filesize directive in php.ini.', 'error');
             $return = FALSE;
             break;
         case UPLOAD_ERR_FORM_SIZE:
             $presenter->flashMessage('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', 'error');
             $return = FALSE;
             break;
         case UPLOAD_ERR_PARTIAL:
             $presenter->flashMessage('The uploaded file was only partially uploaded.', 'error');
             $return = FALSE;
             break;
         case UPLOAD_ERR_NO_FILE:
             if ($noFileError === FALSE) {
                 $presenter->flashMessage('No file was uploaded.', 'error');
             }
             $return = $noFileError;
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
             $presenter->flashMessage('Missing a temporary folder.', 'error');
             $return = FALSE;
             break;
         case UPLOAD_ERR_CANT_WRITE:
             $this->flashMessage('Failed to write file to disk.', 'error');
             $return = FALSE;
             break;
         case UPLOAD_ERR_EXTENSION:
             $presenter->flashMessage('File upload stopped by extension.', 'error');
             $return = FALSE;
             break;
         default:
             $presenter->flashMessage('Chyba při zpracování souboru ' . $file->getName(), 'error');
             $return = FALSE;
             break;
     }
     return $return;
 }
Пример #3
0
 /**
  * Stores the given uploaded file.
  *
  * @param  FileUpload $upload
  * @param  meta       $meta
  * @return ImageStorage Fluent interface
  * @throws UploaderException
  */
 public function upload(FileUpload $upload, Meta $meta)
 {
     if ($upload->getError()) {
         throw new UploaderException($upload->getError());
     }
     $source = $upload->getTemporaryFile();
     $this->readMeta($source, $meta);
     $target = $this->createFilename($meta);
     if (!$this->contains($meta)) {
         $image = Image::fromFile($source);
         $image->resize(1920, 1080);
         $image->save($target);
     }
     if (file_exists($source)) {
         unlink($source);
     }
     return $this;
 }
Пример #4
0
 /**
  * @param FileUpload $fileUpload
  * @param NULL|string $dir
  * @return SplFileInfo
  * @throws UploadErrorException
  */
 public function singleFileToDir(FileUpload $fileUpload, $dir = NULL)
 {
     if ($error = $fileUpload->getError()) {
         throw new UploadErrorException($error);
     }
     $name = $fileUpload->isImage() ? 'imageManager' : 'fileManager';
     /** @var IUploadManager $usedManager */
     $usedManager = $this->{$name};
     $path = Utils::normalizePath($usedManager->getRelativePath() . '/' . $dir);
     $this->onFileBegin($fileUpload, $path);
     $uploadedFile = $usedManager->upload($fileUpload, $dir);
     $this->onFileComplete($fileUpload, $uploadedFile, $path);
     return $uploadedFile;
 }
Пример #5
0
 /**
  * @param Nette\Http\FileUpload $fileUpload
  * @return self
  */
 public static function createFromNetteFileUpload(Nette\Http\FileUpload $fileUpload)
 {
     $new = new self(['name' => Strings::webalize($fileUpload->getName(), '_.'), 'type' => $fileUpload->getContentType(), 'size' => $fileUpload->getSize(), 'tmp_name' => $fileUpload->getTemporaryFile(), 'error' => $fileUpload->getError()]);
     return $new;
 }
Пример #6
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'));
 }