Example #1
0
 public function handleUploadReciever()
 {
     //ob_start();
     $uploader = new \UploadHandler();
     $uploader->allowedExtensions = ["jpeg", "jpg", "png", "gif"];
     $uploader->chunksFolder = __DIR__ . '/../../www/chunks';
     $name = Nette\Utils\Strings::webalize($uploader->getName(), '.');
     //TODO: picture optimalization (?)
     $result = $uploader->handleUpload(__DIR__ . '/../../../www/uploads', $name);
     try {
         $picture = $this->pictures->findOneBy(['uuid' => $uploader->getUuid()]);
         if (!$picture) {
             //FIXME: toto není optimální (zejména kvůli rychlosti)
             $picture = new Entity\Picture();
         }
         $picture->uuid = $uploader->getUuid();
         $picture->name = $name;
         $picture->created = new \DateTime('now');
         $this->pictures->save($picture);
     } catch (\Exception $exc) {
         $uploader->handleDelete(__DIR__ . '/../../www/uploads');
         $this->sendResponse(new Nette\Application\Responses\JsonResponse(['error' => $exc->getMessage()]));
     }
     //TODO: napřed předat do šablony nová data
     $this->redrawControl('pictures');
     $this->sendResponse(new Nette\Application\Responses\JsonResponse($result));
 }