Пример #1
0
 public function handleUpload()
 {
     $file = $this->httpRequest->getFile('Filedata');
     if ($file->isOk()) {
         $this->onUpload($file, $this->httpRequest->getPost());
     } else {
         $this->onError($file->getError());
     }
     $this->presenter->terminate();
 }
Пример #2
0
 /**
  * it's not only handleGallerySaveImage now. We use it for save texy images too
  */
 public function handleSaveImage()
 {
     if ($this->mainManager instanceof MagicManager && $this->mainManager->isGallery()) {
         $folder = $this->mainManager->getGalleryFolder();
     } else {
         $this->error();
     }
     if ($folder == '') {
         $folder = 'misc';
     }
     $file = $this->httpRequest->getFile('Filedata');
     if ($file && $file->isOk() && $this->detailObject) {
         // 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);
         $size = $image->getSize();
         // Prepare thumbnail
         $this->imgPipe->setNamespace($namespace);
         $this->imgPipe->request($filename, '100x100', 'exact');
         // Save to database
         $this->mainManager->addGalleryImage($filename, $namespace, $size->getWidth(), $size->getHeight(), $file->getContentType(), $this->detailObject->id);
         $response = ['status' => '1', 'height' => $size->getHeight(), 'width' => $size->getWidth(), 'mime' => $file->getContentType()];
     } else {
         $response = ['status' => '0', 'error' => 'Error while uploading file', 'code' => 500];
     }
     $this->sendJson($response);
 }
Пример #3
0
 /**
  * TODO: refactor use Aprila/Brick/ImageManager
  */
 public function handleSaveImage()
 {
     $this->imageStorage->setNamespace("texy");
     $onlinePath = 'texy/';
     $response = array();
     /** @var \Nette\Http\FileUpload $file */
     if ($file = $this->httpRequest->getFile('file')) {
         $filename = uniqid() . '.' . (pathinfo($file->name, PATHINFO_EXTENSION) ?: 'png');
         $image = $this->imageStorage->save($file->getContents(), $filename);
         $returnPath = pathinfo($image->file, PATHINFO_BASENAME);
         if (FALSE) {
             // $this->someManager->assignImageToObject($this->object->id, $returnPath, "texy");
         }
         $response['filename'] = $onlinePath . pathinfo($image->file, PATHINFO_BASENAME);
     } else {
         $response['error'] = 'Error while uploading file';
     }
     $this->sendJson($response);
 }
Пример #4
0
 public function handleSaveImage()
 {
     $file = $this->httpRequest->getFile('Filedata');
     if ($file && $file->isOk()) {
         $year = date('Y');
         $month = date('m');
         $namespace = "project/{$year}/{$month}";
         $this->imageStorage->setNamespace($namespace);
         $tempFilename = uniqid() . '.' . (pathinfo($file->getName(), PATHINFO_EXTENSION) ?: 'jpg');
         $image = $this->imageStorage->save($file->getContents(), $tempFilename);
         $size = $image->getSize();
         $colorInfo = $this->getImageColorInfo($image->getFile());
         $filename = pathinfo($image->getFile(), PATHINFO_BASENAME);
         $this->addImage($filename, $namespace, $size->getWidth(), $size->getHeight(), $colorInfo, $file->getName(), $file->getContentType());
         // Prepare thumbnail
         $this->imgPipe->setNamespace($namespace);
         $this->imgPipe->request($filename, '100x100', 'exact');
         $response = ['status' => '1', 'height' => $size->getHeight(), 'width' => $size->getWidth(), 'mime' => $file->getContentType()];
     } else {
         $response = ['status' => '0', 'error' => 'Error while uploading file', 'code' => 500];
     }
     $this->sendJson($response);
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 public function getFile($key)
 {
     return $this->current->getFile($key);
 }