public function getfileAction($hashvalue) { $da_im = $this->get("we_data_access_im"); $sqls = "select fileid from im_lib_files where filepath=?"; $all_params = array((string) $hashvalue); $ds = $da_im->getData("t", $sqls, $all_params); if ($ds && count($ds["t"]["rows"]) > 0) { $mongoDoc = new \Justsy\MongoDocBundle\Controller\DefaultController(); $mongoDoc->setContainer($this->container); return $mongoDoc->getFileAction($ds["t"]["rows"][0]["fileid"]); } else { $response = new Response("", 404); //$response->headers->set('Last-Modified', $_SERVER['HTTP_IF_MODIFIED_SINCE']); return $response; } }
public function viewAction() { $request = $this->get("request"); $fileid = $request->get("fileid"); $fileinfo = new \Justsy\MongoDocBundle\Controller\DefaultController(); $fileinfo->setContainer($this->container); $info = $fileinfo->getFileInfo($fileid); $downpath = $this->generateUrl('JustsyMongoDocBundle_downfile', array('id' => $fileid)); if ($info == null) { $path = ""; } else { $s = strtolower($info["filename"]); $path = $this->container->getParameter('FILE_WEBSERVER_URL') . $fileid; if (preg_match("/\\.jpg|\\.bmp|\\.gif|\\.jpeg|\\.png\$/", $s)) { return $this->render('JustsyBaseBundle:DocumentMgr:view_image.html.twig', array('path' => $path)); } //判断大小 $extend = explode(".", $s); if (count($extend) == 1) { $fix = ""; } else { $fix = $extend[count($extend) - 1]; } try { $fix = \Justsy\BaseBundle\Common\MIME::$MIMEOtherTable["." . $fix]; } catch (\Exception $e) { } if (("text/plain" == $fix || "text/html" == $fix || "application/x-javascript" == $fix || "*/*" == $fix || empty($fix)) && (int) $info["size"] < 200 * 1024) { return $this->render('JustsyBaseBundle:DocumentMgr:view_other.html.twig', array('type' => $fix, 'path' => $path, 'downpath' => "")); } return $this->render('JustsyBaseBundle:DocumentMgr:view_other.html.twig', array('type' => $fix, 'path' => "", 'downpath' => $downpath)); } return $this->render('JustsyBaseBundle:DocumentMgr:view_other.html.twig', array('path' => "", 'downpath' => "")); }