public function frontendResetAction($id = false) { $response = new Response(); $response->headers->setCookie(new Cookie("subscriber_id", false)); $response->sendHeaders(); return $this->redirect($this->generateUrl('subscriber_frondend_submit', array('id' => $id))); }
/** * @return $this|Response */ public function sendHeaders() { if ($this->mustSendHeaders()) { return parent::sendHeaders(); } return $this; }
/** * @param string $content * @param int $status * @param array $headers * @return Response */ function response_plain($content, $status = Response::HTTP_OK, array $headers = []) { // We have to do a little trick and do not allow WHMCS to sent all it's content. $response = new Response($content, $status, $headers); $response->sendHeaders(); die($response->getContent()); }
/** * @Route("/question/{id}", name="question") */ public function showQuestionAction($id = null, Request $request) { $session = new Session(); $notice = $session->getFlashBag(); $query = $this->getDoctrine()->getRepository('AppBundle:Question'); $size = $query->size(); $response = new Response(); if (!$id) { $response->headers->clearCookie('checked'); $response->sendHeaders(); return $this->redirect($this->generateUrl('question', array('id' => mt_rand(1, $size)))); } $question = $query->find($id); $query = $this->getDoctrine()->getRepository('AppBundle:Choice'); $form = $this->createForm(new QuestionType($question, $query, $size)); $form->handleRequest($request); if ($form->get('next')->isClicked()) { $id = $form->get('questionId')->getViewData() ? $form->get('questionId')->getViewData() : mt_rand(1, $size); return $this->redirect($this->generateUrl('question', array('id' => $id))); } if ($form->isSubmitted() && $form->isValid()) { $currentChoices = $form["choices"]->getViewData(); if (is_array($currentChoices)) { $currentChoices = array_map('current', $currentChoices); } else { $currentChoices = $currentChoices ? array($currentChoices->getId()) : ''; } $rightChoices = $query->getQuestionChoices($id); !array_diff($rightChoices, $currentChoices) ? $notice->add('success', "Congratulation, it's a right answer!") : $notice->add('error', "Sorry, this is wrong answer."); return $this->redirect($this->generateUrl('question', array('id' => $id))); } $imageHelper = new Image($question, $this->get('kernel')); return $this->render('default/questions.html.twig', array('question' => $question, 'form' => $form->createView(), 'image_path' => $imageHelper->getImageAssetPath())); }
public function setGuidCookie($arr) { $gInfo = base64_encode(serialize($arr)); $response = new Response(); $expiration = time() + 3600 * 24 * 365 * 5; $response->headers->setCookie(new Cookie(self::GUID_COOKIE_INFO, $gInfo, $expiration)); $response->sendHeaders(); }
/** * send the http response headers * * overrides the parent to not attempt to send the headers if there was output before this * method was called * * @since 6-30-11 */ public function sendHeaders() { // canary... if (headers_sent()) { return; } //if return parent::sendHeaders(); }
/** * {@inheritdoc} */ public function sendHeaders() { if ($this->config->get('image_captcha_file_format') == IMAGE_CAPTCHA_FILE_FORMAT_JPG) { $this->headers->set('content-type', 'image/jpeg'); } else { $this->headers->set('content-type', 'image/png'); } return parent::sendHeaders(); }
/** * @param array $userInfo */ private function storeUserInfo($userInfo) { $extension = $this->get('app.twig_extension'); $sessionId = $extension->generateSessionId(); $extension->createSession($sessionId, $userInfo); $response = new Response(); $expired = time() + 86400 * 30; $response->headers->setCookie(new Cookie('session_id', $sessionId, $expired)); $response->sendHeaders(); }
/** * @Route("/download", name="filesearch_download") */ public function downloadAction(Request $request) { $filePath = $request->get('path', null); $response = new Response(); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', mime_content_type($filePath)); $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filePath) . '";'); $response->headers->set('Content-length', filesize($filePath)); $response->sendHeaders(); return $response->setContent(file_get_contents($filePath)); }
public function testSendHeaders() { $response = new Response(); $headers = $response->sendHeaders(); $this->assertObjectHasAttribute('headers', $headers); $this->assertObjectHasAttribute('content', $headers); $this->assertObjectHasAttribute('version', $headers); $this->assertObjectHasAttribute('statusCode', $headers); $this->assertObjectHasAttribute('statusText', $headers); $this->assertObjectHasAttribute('charset', $headers); }
/** * @Route("/download/{filename}/{file}", name="app_download") * @Route("/load/{filename}/{file}", name="app_load") * @ParamConverter("file", converter="file_converter") * @Method("GET") * @param string $filename * @param \SplFileObject $file * @return Response */ public function loadAction($filename, \SplFileObject $file) { $response = new Response($file->fpassthru()); $response->headers->set('Content-Type', 'octet/stream'); $response->headers->set('Content-disposition', 'attachment; filename="' . $filename . '.' . $file->getExtension() . '";"'); $response->headers->set('Content-Length', $file->getSize()); $response->headers->set('Cache-Control', 'max-age=31536000, public'); // 1 year $response->sendHeaders(); return $response->send(); }
public function indexAction($id = false, Request $request) { $ticket = $this->getDoctrine()->getRepository('TicketBundle:Ticket')->findOneBy(array('external' => $id)); if ($ticket == null) { return $this->redirect($this->generateUrl('ticket_edit', array('id' => $id))); } $items = $ticket->getSubscribers(); $response = new Response(); $response->headers->setCookie(new Cookie("ticket_id", $id)); $response->sendHeaders(); return $this->render('TicketBundle:Ticket:index.html.twig', array('items' => $items, 'ticket' => $ticket)); }
public function getFileAction($fileName) { $filepath = $this->getFolderPath() . $fileName . '.pdf'; $response = new Response(); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', mime_content_type($filepath)); $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filepath) . '";'); $response->headers->set('Content-length', filesize($filepath)); $response->sendHeaders(); $fileContent = readfile($filepath); unlink($filepath); return $response->setContent($fileContent); }
/** * @Route("/attachment/{id}", name="attachment_download") * @Method({"GET", "POST"}) */ public function indexAction(Request $request, $id) { $em = $this->getDoctrine()->getManager(); $att = $em->getRepository('oGooseBundle:Attachment')->find($id); $filename = $att->getFilename(); $fullPath = '../media/attachments/' . $filename; $response = new Response(); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-Type', mime_content_type($fullPath) . '; charset=utf-8'); $response->headers->set('Content-Disposition', 'attachment;filename="' . $filename . '"'); $response->sendHeaders(); $response->setContent(readfile($fullPath)); return $response; }
/** * @ApiDoc( * description="Attachment download.", * tags={"file"}, * requirements={ * { * "name"="id", * "dataType"="integer", * "description"="attachment id" * } * }, * parameters={ * {"name"="id", "dataType"="integer", "required"=true, "description"="attachment id"} * } * ) * * @Route("/attachment/{id}", name="index_attachment_download") * @Method("GET") */ public function attachmentDownloadAction($id) { $em = $this->getDoctrine()->getManager(); $attachment = $em->getRepository('APPAnswersBundle:Attachment')->find($id); $response = new Response(); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', $attachment->getMimeType()); $response->headers->set('Content-Disposition', 'inline; filename="' . $attachment->getOriginalFilename() . '";'); $response->headers->set('Content-length', $attachment->getSize()); $response->sendHeaders(); $file = $attachment->getSystemPath() . $attachment->getSystemFilename(); $response->setContent(readfile($file)); return $response; }
/** * Download log file * * @param integer $id * @return Response */ public function downloadAction($id) { $log = $this->getDoctrine()->getManager()->getRepository('CoreBundle:ImportLog')->findOneBy(['id' => $id]); if ($log && file_exists($log->getFilename())) { $response = new Response(); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', mime_content_type($log->getFilename())); $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($log->getFilename()) . '";'); $response->headers->set('Content-length', filesize($log->getFilename())); $response->sendHeaders(); $response->setContent(readfile($log->getFilename())); return $response; } else { return new Response('File not found', 404); } }
/** * @Route("/api/files/{filename}") * @Method({"GET"}) */ public function getFileAction(Request $request, $filename) { $filesystem = $this->container->get('local'); if (!$filesystem->has($filename)) { $data = ['error' => 404, 'error_message' => "File Not Found"]; $view = $this->view($data, 404); return $this->handleView($view); } $response = new Response(); $response->headers->set('Content-Type', $filesystem->getMimetype($filename)); $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filename) . '";'); $response->headers->set('Content-length', $filesystem->getMimetype($filename)); $response->sendHeaders(); $response->setContent($filesystem->read($filename)); return $response; }
public function robotsAction(Request $request) { $host = $request->headers->get('host'); $cacheId = 'robots_txt'; $env = $this->get('kernel')->getEnvironment(); $site = $this->getSite(); if (!$site) { $response = $this->render('CMFTemplateBundle:Status:404.html.twig'); $response->setStatusCode(404); return $response; } $response = new Response(); $response->headers->set('Content-Type', 'text/plain'); $response->sendHeaders(); $response->setContent($site['robots_txt']); return $response; }
private function prepareResponse(File $file, $filename = null) { $mimeType = $file->getMimeType(); if ($mimeType == 'application/pdf') { $disposition = 'inline'; } else { $disposition = 'attachment'; } $response = new Response(); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-Type', $mimeType); $response->headers->set('Content-Disposition', $disposition . '; filename="' . ($filename ? $filename : $file->getFilename()) . '"'); $response->headers->set('Content-Length', $file->getSize()); $response->sendHeaders(); readfile($file); return $response; }
public function VisualAction($document) { // Generate response $response = new Response(); // Set headers $filepath = $this->get('kernel')->getRootDir() . "/uploads/formations_documents/" . $document; $oFile = new File($filepath); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', $oFile->getMimeType()); $response->headers->set('Content-Disposition', 'inline; filepath="' . $oFile->getBasename() . '";'); $response->headers->set('Content-length', $oFile->getSize()); // filename // Send headers before outputting anything $response->sendHeaders(); $response->setContent(file_get_contents($filepath)); return $response; }
/** * @Route("/get/{format}/{id}", name="ticket_get_big_img") * @param $id * @param $format * @return Response */ public function getTicketBigImage($id, $format) { $mediaManager = $this->get('sonata.media.manager.media'); $media = $mediaManager->findOneBy(['id' => $id]); if ($media) { $repository = $this->getDoctrine()->getRepository('DreamlexTicketBundle:Message'); $message = $repository->findOneBy(['media' => $media->getId()]); if ($message->getTicket()->getUser() === $this->getUser() || $this->get('security.authorization_checker')->isGranted('ROLE_TICKET_ADMIN')) { $provider = $this->get('sonata.media.provider.ticket_image'); $file = $provider->generateCustomUrl($media, $format); $response = new Response(); $response->headers->set('X-Accel-Redirect', $file); $response->headers->set('Content-type', $media->getContentType()); return $response->sendHeaders(); } } throw $this->createNotFoundException(); }
/** * {@inheritdoc} */ public function serve($params = null) { $uri = $params; if (!class_exists('SoapServer')) { throw new \Exception('SoapServer is required. Please enable this extension'); exit; } if (!class_exists('Zend\\Soap\\Server')) { throw new \Exception("Zend\\Soap\\Server is required. " . "Please install it using 'composer require zend/zend-soap'"); exit; } $serviceHandler = get_class($this->serviceHandler); $obj = new $serviceHandler($this->authentication, $this->connectionStrings, $this->logDir); if (null === $uri) { $uri = strtok($this->request->getUri(), '?'); $uri = dirname($uri) . '/' . basename($uri); } $response = new Response(); $response->headers->set('Access-Control-Allow-Headers', 'origin, content-type, accept'); $response->headers->set('Access-Control-Allow-Origin', '*'); $response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS'); $response->headers->set('Content-type', 'text/xml'); $cacheFile = dirname($_SERVER['SCRIPT_FILENAME']) . '/dbinstance.wsdl.xml'; if (isset($_GET['wsdl']) || isset($_GET['WSDL'])) { $xml = ''; if (file_exists($cacheFile)) { $xml = file_get_contents($cacheFile); } else { $autodiscover = new AutoDiscover(); $autodiscover->setUri($uri); $autodiscover->setClass($serviceHandler); $autodiscover->setServiceName('DBInstance'); $wsdl = $autodiscover->generate(); $xml = $wsdl->toXml(); $wsdl->dump($cacheFile); } $response->setContent($xml); return $response->send(); } $response->sendHeaders(); $server = new Server($uri . '?wsdl'); $server->setObject($obj); $server->handle(); }
/** * * @param $photo_file * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response */ public function getPhotoAction($photo_id) { if (!$this->getUser()) { return $this->redirectToRoute('fos_user_security_login'); } $photo_file = $this->get('doctrine')->getRepository('IuchBundle:Photo')->findOneById($photo_id)->getNom(); // Generate response $response = new Response(); $filepath = $this->get('kernel')->getRootDir() . "/uploads/photos/" . $photo_file; $photoFile = new File($filepath); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', $photoFile->getMimeType()); $response->headers->set('Content-Disposition', 'inline; filepath="' . $photoFile->getBasename() . '";'); $response->headers->set('Content-length', $photoFile->getSize()); // Send headers before outputting anything $response->sendHeaders(); $response->setContent(file_get_contents($filepath)); return $response; }
/** * this action shows the suggestion page or creates/adds a new suggestion for the month depending on the request Method * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response */ public function addSuggestionAction(Request $request) { $status = $this->get('nerdery_sna_foo.model.snack_api')->testApiConnection(); if (!$status) { return $this->render('NerderySnaFooBundle::apiDown.html.twig'); } $suggestion = new Suggestion(); $form = $this->createForm($this->get('nerdery_sna_foo.form.suggestion_type'), $suggestion, array('action' => $this->generateUrl('add_suggestion'), 'method' => 'POST')); if ($request->getMethod() == 'POST') { // if a suggested snack was already created for the month then show error message if (!$this->checkForErrors('suggestionAlreadyCreated')) { return $this->redirectToRoute('add_suggestion'); } $form->handleRequest($request); if ($form->isValid()) { // if that snack already exists then show an error message if (!$this->checkForErrors('duplicateSnack', $suggestion)) { return $this->redirectToRoute('add_suggestion'); } // save the snack to the nerdery api endpiont $snackId = $this->saveSnackToNerderyApi($suggestion); // create a monthly snack in the database $monthlySnack = new MonthlySnack(); $monthlySnack->setSnack($snackId); $vote = new Vote(); $vote->setMonthlySnack($monthlySnack); $vote->setCount(0); $em = $this->getDoctrine()->getManager(); $em->persist($monthlySnack); $em->persist($vote); $em->flush(); // set a cookie saying the user suggested a snack for the month $response = new Response(); $time = time() + 3600 * 24 * 30; $response->headers->setCookie(new Cookie('suggestedASnack', true, $time, '/', null, false, false)); $response->sendHeaders(); $this->addFlash('successMessage', 'Suggestion Successfully Added'); return $this->redirectToRoute('add_suggestion'); } } return $this->render('NerderySnaFooBundle:Suggestions:addSuggestion.html.twig', array('form' => $form->createView())); }
public function PictureOrganismeAction($picture) { if (!$this->getUser()) { return $this->redirectToRoute('fos_user_security_login'); } // Generate response $response = new Response(); // Set headers $filepath = $this->get('kernel')->getRootDir() . "/uploads/organismes_pictures/" . $picture; $oFile = new File($filepath); $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', $oFile->getMimeType()); $response->headers->set('Content-Disposition', 'inline; filepath="' . $oFile->getBasename() . '";'); $response->headers->set('Content-length', $oFile->getSize()); // filename // Send headers before outputting anything $response->sendHeaders(); $response->setContent(file_get_contents($filepath)); return $response; }
public static function sendResponse($name, $data, Request $request) { $objPHPExcel = self::getExcelFromData($name, $data); $fileNameTemplate = '%s.%s'; $fileName = sprintf($fileNameTemplate, $name, self::EXTENSION_EXCEL); $contentTypeHeaderTemplate = '%s; name="%s"'; $contentTypeHeader = sprintf($contentTypeHeaderTemplate, self::MIME_TYPE_EXCEL, $fileName); $contentDispositionHeaderTemplate = 'attachment; filename="%s"'; $contentDispositionHeader = sprintf($contentDispositionHeaderTemplate, $fileName); $response = new Response(); $response->headers->set('Content-Type', $contentTypeHeader); $response->headers->set('Pragma', 'no-cache'); $response->headers->set('Expires', '0'); $response->headers->set('Content-Disposition', $contentDispositionHeader); $response->prepare($request); $response->sendHeaders(); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); exit; }
public static function sendResponse($name, $data, Request $request) { $fileNameTemplate = '%s.%s'; $fileName = sprintf($fileNameTemplate, $name, self::EXTENSION_CSV); $contentTypeHeaderTemplate = '%s; name="%s"'; $contentTypeHeader = sprintf($contentTypeHeaderTemplate, self::MIME_TYPE_CSV, $fileName); $contentDispositionHeaderTemplate = 'attachment; filename="%s"'; $contentDispositionHeader = sprintf($contentDispositionHeaderTemplate, $fileName); $response = new Response(); $response->headers->set('Content-Type', $contentTypeHeader); $response->headers->set('Pragma', 'no-cache'); $response->headers->set('Expires', '0'); $response->headers->set('Content-Disposition', $contentDispositionHeader); $response->prepare($request); $response->sendHeaders(); $fp = fopen('php://output', 'w'); foreach ($data as $row) { fputcsv($fp, $row); } fclose($fp); exit; }
public function robotsAction(Request $request) { $host = $request->headers->get('host'); $cacheId = 'robots_txt'; $env = $this->get('kernel')->getEnvironment(); $cache = new \Doctrine\Common\Cache\FilesystemCache($_SERVER['DOCUMENT_ROOT'] . '/../app/cache/' . $env . '/sys/' . $host . '/etc/'); //$cache = new \Doctrine\Common\Cache\ApcCache(); if ($fooString = $cache->fetch($cacheId)) { $response = unserialize($fooString); } else { $site = $this->getSite(); if (!$site) { $response = $this->render('CMFTemplateBundle:Status:404.html.twig'); $response->setStatusCode(404); return $response; } $response = new Response(); $response->headers->set('Content-Type', 'text/plain'); $response->sendHeaders(); $response->setContent($site['robots_txt']); $cache->save($cacheId, serialize($response)); } return $response; }
public function descargaAdjuntoAction($id, Request $request) { $em = $this->getDoctrine()->getManager(); $archivo = $em->find('AdminBundle:Archivo', $id); // ¿A qué comunidad pertenece este archivo? $comunidad = $archivo->getMensaje()->getComunidad()->getId(); // ¿Posee el usuario actual permiso sobre archivos de esa comunidad? $user = $this->getUser(); $comunidades = $user->getComunidades(); if ($user->getRol() == 1 || in_array($comunidad, $comunidades)) { $path = realpath(__DIR__ . '/../../../../uploads/files') . '/' . $archivo->getPath(); // Vamos a mostrar un PDF $response = new Response(); // Set headers $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', 'application/unknown'); $response->headers->set('Content-Disposition', 'attachment; filename="' . $archivo->getName() . '";'); $response->headers->set('Content-length', filesize($path)); // Send headers before outputting anything $response->sendHeaders(); $response->setContent(readfile($path)); return $response; } // No posee permiso sobre ese archivo // No se notifica // Se redirecciona a la página de inicio $rol = $user->getRol(); switch ($rol) { case 1: return $this->redirect($this->generateUrl('admin_index')); break; case 2: return $this->redirect($this->generateUrl('user_index', array('id' => 'default'))); break; } }
/** * Get a Response object to force download document. * * This method works for both private and public documents. * * **Be careful, this method will send headers.** * * @return Symfony\Component\HttpFoundation\Response */ public function getDownloadResponse() { $response = new Response(); // Set headers $response->headers->set('Cache-Control', 'private'); $response->headers->set('Content-type', mime_content_type($this->document->getAbsolutePath())); $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($this->document->getAbsolutePath()) . '";'); $response->headers->set('Content-length', filesize($this->document->getAbsolutePath())); // Send headers before outputting anything $response->sendHeaders(); // Set content $response->setContent(readfile($this->document->getAbsolutePath())); return $response; }