/** * @param PostPersistEvent $event * @return AbstractResponse * @throws \UnexpectedValueException|\InvalidArgumentException */ public function onUpload(PostPersistEvent $event) { $file = $event->getFile(); if (!$file instanceof GaufretteFile) { $class = get_class($file); throw new \UnexpectedValueException("Only gaufrette files are supported, '{$class}' given"); } $originalFilename = $file->getName(); try { // Couldn't find anything better with OneUp uploader... $originalFiles = $event->getRequest()->files->all(); if (isset($originalFiles['files'])) { $originalFiles = $originalFiles['files']; if (count($originalFiles)) { $originalFile = array_pop($originalFiles); $originalFilename = $originalFile->getClientOriginalName(); } } } catch (\Exception $e) { } $file = $this->resourceManager->addFile($file, $originalFilename, $event->getType()); /** @var AbstractResponse $response */ $response = $event->getResponse(); $response[] = $file; return $response; }
public function onUpload(PostPersistEvent $event) { $response = $event->getResponse(); /** @var File $file */ $file = $event->getFile(); $uploadType = $event->getType(); $filePath = $file->getPathName(); $fileName = $file->getFileName(); $fileSize = $file->getSize(); $fileMimeType = $file->getMimeType(); // move to folder or create a nested folder structure $fileHelper = new FileHelper(); $uploadRootPath = $this->rootDir . '/../web/uploads/' . $uploadType . '/'; /** * @var string $uploaNestedDirs generated nested folder structure under rootpath. c33b/f671/1712/ */ $nestedDirs = $fileHelper->generatePath($fileName, true, $uploadRootPath); rename($filePath, $uploadRootPath . $nestedDirs . $fileName); $fileDir = $uploadRootPath . $nestedDirs; $uploadUrl = str_replace($uploadRootPath, $uploadType, $fileDir); if ($uploadType === 'avatarfiles') { $helper = new ImageResizeHelper(array('image_name' => $fileName, 'upload_dir' => $fileDir, 'upload_url' => $uploadUrl)); $helper->resize(); } $response['files'] = array('name' => $file->getFileName(), 'path' => $fileHelper->generatePath($file->getFileName(), false), 'size' => $fileSize, 'url' => '', 'mimeType' => $fileMimeType, 'fullpath' => DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $uploadType . DIRECTORY_SEPARATOR . $fileHelper->generatePath($file->getFileName(), false)); return $response; }
public function onUpload(PostPersistEvent $event) { $request = $event->getRequest(); $mediaType = $request->get('mediaType'); $providerName = $mediaType == 'image' ? 'sonata.media.provider.image' : 'sonata.media.provider.file'; $context = $request->get('context'); $categoryId = $request->get('category'); if ($categoryId) { $category = $this->categoryManager->find($categoryId); } else { $category = $this->getRootCategory($context); } $file = $event->getFile(); $media = new Media(); $media->setProviderName($providerName); $media->setContext($context); $media->setCategory($category); $media->setBinaryContent($file); //TODO - improve the retrieval of the file name if (is_array(current($request->files)) && is_array(current(current($request->files)))) { $media->setName(current(current($request->files))[0]->getClientOriginalName()); } $provider = $this->pool->getProvider($providerName); $provider->transform($media); $this->manager->save($media); $mediaAdmin = $this->container->get('orangegate.media.admin.media'); $response = $event->getResponse(); $response['name'] = $media->getName(); $response['size'] = $media->getSize(); $response['url'] = $mediaType == 'image' ? $provider->generatePublicUrl($media, $provider->getFormatName($media, 'orangegate')) : $mediaAdmin->generateObjectUrl('edit', $media); $response['id'] = $media->getId(); $response['mediaType'] = $mediaType; $response['contentType'] = $media->getContentType(); @unlink($file->getPathname()); }
public function onUpload(PostPersistEvent $event) { $response = $event->getResponse(); /** @var FileInterface $file */ $file = $event->getFile(); $response['file'] = $file->getBasename(); }
public function onUpload(PostPersistEvent $event) { $file = $event->getFile(); $path = '/uploads/' . $event->getType() . '/' . $file->getFilename(); $response = $event->getResponse(); $response['key'] = 'value'; $response['foo'] = 'bar'; $response['name'] = $file->getFilename(); $response['path_raw'] = $path; }
public function onUpload(PostPersistEvent $event) { $request = $event->getRequest(); $ent_t = $request->get('entity'); $ent_a = explode("_", $ent_t); $id = $request->get('id'); eval("\$reEntity = \$this->doctrine->getRepository('" . $ent_a[0] . $ent_a[1] . ":" . $ent_a[2] . "');"); if ($id == 0) { eval("\$entity = new \\" . $ent_a[0] . "\\" . $ent_a[1] . "\\Entity\\" . $ent_a[2] . "();"); } else { $entity = $reEntity->findOneById($id); if ($entity == null) { eval("\$entity = new \\" . $ent_a[0] . "\\" . $ent_a[1] . "\\Entity\\" . $ent_a[2] . "();"); } } foreach ($request->request->all() as $key => $value) { $temp = explode("_", $key); if ($temp[0] == "add") { if (count($temp) == 2) { eval("\$entity->set" . ucfirst($temp[1]) . "('" . $value . "');"); } else { eval("\$reTemp = \$this->doctrine->getRepository('" . $temp[1] . $temp[2] . ":" . $temp[3] . "');"); $easig = $reTemp->findOneById($value); if ($easig == null) { eval("\$entity->set" . ucfirst($temp[3]) . "(null);"); } else { eval("\$entity->set" . ucfirst($temp[3]) . "(\$easig);"); } } } } $entity->setPath($event->getFile()->getRealPath()); $entity->setDir($event->getType()); $this->doctrine->getManager()->persist($entity); $this->doctrine->getManager()->flush(); //$entity = new \iCofrade\BaseBundle\Entity\Image(); // echo $entity->getPath(); //$gallery = $request->get('gallery'); // $gallery = $request->get('gallery'); //$log = new Logger('name'); //$log->pushHandler(new StreamHandler('/var/www/icofrade/your.log', Logger::WARNING)); // $log->addError($request->getUriForPath($event->getFile())); // add records to the log // Variable $log->addWarning("Gallery: "+$gallery); // $log->addError($event->getType()); // $log->addError($event->getFile()); // $log->addError($event->getFile()->getRealPath()); // $log->addError($event->getFile()->getUrl()); // ldd($request); $response = $event->getResponse(); $response['id'] = $entity->getId(); $response['entity'] = $request->get('entity'); }
public function onUpload(PostPersistEvent $event) { $response = $event->getResponse(); /** @var GaufretteFile $file */ $file = $event->getFile(); $avatarPath = $file->getPathname(); $mimeType = $file->getMimeType(); $rename = $file->getFilesystem()->rename($file->getPathname(), $event->getType() . '/' . $avatarPath); if ($rename) { $avatarPath = $event->getType() . '/' . $avatarPath; } $imageSize = getimagesize('gaufrette://images/' . $avatarPath); $response['path'] = $avatarPath; $response['url'] = $this->fileUploadService->getPublicUrl($avatarPath); $response['type'] = $mimeType; list($response['width'], $response['height']) = $imageSize; if ($event->getType() == 'avatar') { $event->getRequest()->getSession()->set('campaignchain_last_uploaded_avatar', $avatarPath); } }
public function onUpload(PostPersistEvent $event) { $file = $event->getFile(); /* @var $file \Symfony\Component\HttpFoundation\File\File */ $request = $event->getRequest(); $response = $event->getResponse(); $r = array(); $em = $this->doctrine->getEntityManager(); if ($request->get('attachment')) { $contratto = $em->getRepository('CasaFront2Bundle:Contratto')->find($request->get('attachment')); $documento = new Documento(); $documento->setFile('upload/' . $contratto->getId() . '/documenti/' . $file->move('upload/' . $contratto->getId() . '/documenti/', $file->getFileName())->getFileName()); $documento->setContratto($contratto); $r = array('name' => $file->getFilename(), 'url' => str_replace('app_dev.php/', '', $this->router->generate('home', array(), true)) . 'uploads/attachment/' . $file->getFilename()); $documento->setJson($r); $em->persist($documento); $em->flush(); } elseif ($request->get('contratto_id')) { $contratto = $em->getRepository('CasaFront2Bundle:Contratto')->find($request->get('contratto_id')); /* @var $contratto \Casa\Front2Bundle\Entity\Contratto */ $foto = new Foto(); $foto->setContratto($contratto); $foto->setFile($file->getFilename()); $foto->setPrincipale(count($contratto->getFoto()) == 0); $em->persist($foto); $em->flush(); $r = array('name' => $file->getFilename(), 'size' => $file->getSize(), 'type' => $file->getMimeType(), 'url' => str_replace('app_dev.php/', '', $this->router->generate('home', array(), true)) . 'uploads/gallery/' . $foto->getFile()); // Image sizes (x >= y): $size = array('bigImage' => array('x' => 1024, 'y' => 768), 'mediumImage' => array('x' => 600, 'y' => 400), 'thumbnail' => array('x' => 300, 'y' => 227), 'icon' => array('x' => 64, 'y' => 64)); $this->gdResize($size, $file, $r); $foto->setJson($r); $em->persist($foto); $em->flush(); } else { unlink($file->getRealPath()); $response['error'] = "File format don't supported"; } $response['files'] = array($r); }