Ejemplo n.º 1
0
 private function saveFile($path, $dm)
 {
     $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
     $doc->setName(basename($path));
     $doc->setFile($path);
     $dm->persist($doc);
     $dm->flush();
     unlink($path);
     return $doc->getId();
 }
Ejemplo n.º 2
0
 private function saveFile($path)
 {
     $dm = $this->containerObj->get('doctrine.odm.mongodb.document_manager');
     $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
     $doc->setName(basename($path));
     $doc->setFile($path);
     $dm->persist($doc);
     $dm->flush();
     unlink($path);
     return $doc->getId();
 }
Ejemplo n.º 3
0
 public function IndexAction()
 {
     $da = $this->get("we_data_access");
     $user = $this->get('security.context')->getToken()->getUser();
     $eno = $user->eno;
     $username = $user->getUsername();
     $request = $this->getRequest();
     $logo = $request->get("fileid");
     $crop = $request->get("crop");
     $type = $request->get("type");
     $index = $request->get("index");
     if (empty($type)) {
         $re = array("success" => false, "msg" => "请输入type参数值");
         $result = new Response(json_encode($re));
         $result->headers->set('Content-Type', 'text/json');
         return $result;
     }
     $width = 0;
     $height = 0;
     if ($type == 1) {
         $width = 180;
         $height = 180;
     } else {
         if ($type == 2) {
             $width = 400;
             $height = 130;
         } else {
             if ($type == 3) {
                 $width = 640;
                 $height = 1136;
             }
         }
     }
     if (!empty($crop)) {
         $crop = json_decode($crop, true);
     }
     $appid = $request->get("appid");
     $success = true;
     $newfileid = "";
     if (!empty($logo) && !empty($crop)) {
         //源图像另存为
         $doc = $this->get('doctrine.odm.mongodb.document_manager')->getRepository('JustsyMongoDocBundle:WeDocument')->find($logo);
         if (!empty($doc)) {
             $filename1 = strtolower($doc->getName());
             $expname = explode(".", $filename1);
             $expname = $expname[1];
             $src = tempnam(sys_get_temp_dir(), "tmp") . "." . $expname;
             $file = $doc->getFile();
             $filename2 = $file->getFilename();
             $tybes = $file->getBytes();
             $cont = fopen($src, 'w');
             fwrite($cont, $tybes);
             fclose($cont);
             $gd = new \Justsy\BaseBundle\Common\Gd();
             $gd->open($src);
             if ($gd->is_image()) {
                 $gd->crop((int) $crop["x"], (int) $crop["y"], (int) $crop["w"], (int) $crop["h"]);
                 $gd->resize_to($width, $height, 'force');
                 $gd->save_to($src);
                 $dm = $this->get('doctrine.odm.mongodb.document_manager');
                 $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
                 $doc->setName(basename($src));
                 $doc->setFile($src);
                 $dm->persist($doc);
                 $dm->flush();
                 $newfileid = $doc->getId();
             }
             unlink($src);
             //数据记录操作处理
             $field = "";
             if ($type == 1) {
                 $sql = "update we_apps_portalconfig set logo=? where appid=?";
                 $field = "logo as fileid";
             } else {
                 if ($type == 2) {
                     $sql = "update we_apps_portalconfig set login_image=? where appid=?";
                     $field = "login_image as fileid";
                 } else {
                     if ($type == 3) {
                         $sql = "update we_apps_portalconfig set start_image=? where appid=?";
                         $field = "start_image as fileid";
                     } else {
                         if ($type == 4) {
                             $sql = "update we_apps_portalconfig set guide" . $index . "=? where appid=?";
                             $field = "guide" . $index . " as fileid";
                         }
                     }
                 }
             }
             $params = array((string) $newfileid, $appid);
             //记录原来文件id
             $remove_fileid = "";
             try {
                 $remove_sql = "select " . $field . " from we_apps_portalconfig where appid=?;";
                 $ds = $da->GetData("table", $remove_sql, array((string) $appid));
                 if ($ds && $ds["table"]["recordcount"] > 0) {
                     $remove_fileid = $ds["table"]["rows"][0]["fileid"];
                 }
             } catch (\Exception $e) {
             }
             $dm = $this->get('doctrine.odm.mongodb.document_manager');
             Utils::removeFile($logo, $dm);
             try {
                 $da->ExecSQL($sql, $params);
                 //更改成功后删除原mogo文件
                 Utils::removeFile($remove_fileid, $dm);
             } catch (\Exception $e) {
                 $success = false;
                 $this->get("logger")->err($e->getMessage());
             }
         }
     }
     $re = array("success" => $success, "fileid" => $newfileid);
     $result = new Response(json_encode($re));
     $result->headers->set('Content-Type', 'text/json');
     return $result;
 }
Ejemplo n.º 4
0
 protected function saveCertificate($filetemp, $filename)
 {
     $result = array();
     try {
         $upfile = tempnam(sys_get_temp_dir(), "we");
         unlink($upfile);
         if (move_uploaded_file($filetemp, $upfile)) {
             $dm = $this->get('doctrine.odm.mongodb.document_manager');
             $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
             $doc->setName($filename);
             $doc->setFile($upfile);
             $dm->persist($doc);
             $dm->flush();
             $fileid = $doc->getId();
             return $fileid;
         } else {
             return "";
         }
     } catch (\Exception $e) {
         $this->get('logger')->err($e);
         $result = array("fileid" => "", "filepath" => "");
         return "";
     }
 }
Ejemplo n.º 5
0
 private function saveFile($filename)
 {
     $fileid = "";
     try {
         if (!empty($filename) && file_exists($filename)) {
             $newfile = sys_get_temp_dir() . "/" . basename($filename);
             if (rename($filename, $newfile)) {
                 //进行mongo操作
                 $dm = $this->get('doctrine.odm.mongodb.document_manager');
                 $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
                 $doc->setName(basename($newfile));
                 $doc->setFile($newfile);
                 $dm->persist($doc);
                 $dm->flush();
                 $fileid = $doc->getId();
                 //存入mongo后删除源文件
                 if (file_exists($filename)) {
                     unlink($filename);
                 }
             }
         }
     } catch (\Exception $e) {
         $this->get("logger")->err($e);
         $fileid = "";
     }
     return $fileid;
 }
Ejemplo n.º 6
0
 public function fileuploadAction()
 {
     $re = array("returncode" => ReturnCode::$SUCCESS);
     $request = $this->getRequest();
     $user = $this->get('security.context')->getToken()->getUser();
     $filename = $request->get("filename");
     $circle_id = $request->get("circle_id");
     $group_id = $request->get("group_id");
     // multipart/form-data
     try {
         if (empty($filename) || empty($circle_id) || empty($group_id)) {
             throw new \Exception("param is null");
         }
         if (!isset($_FILES['userfile'])) {
             $upfile = tempnam(sys_get_temp_dir(), "we");
             unlink($upfile);
             $somecontent1 = base64_decode($request->get('filedata'));
             if ($handle = fopen($upfile, "w+")) {
                 if (!fwrite($handle, $somecontent1) == FALSE) {
                     fclose($handle);
                 }
             }
         } else {
             $upfile = $_FILES['userfile']['tmp_name'];
         }
         $isimage = preg_match(\Justsy\BaseBundle\Common\MIME::getMIMEImgReg(), strtolower($filename));
         $imagefilename_small = preg_replace("/(\\.[^\\.]*)\$/", '_small\\1', $filename);
         $imagefilename_middle = preg_replace("/(\\.[^\\.]*)\$/", '_middle\\1', $filename);
         $imagefilepath_small = $upfile . "." . $imagefilename_small;
         $imagefilepath_middle = $upfile . "." . $imagefilename_middle;
         $dm = $this->get('doctrine.odm.mongodb.document_manager');
         $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
         $doc->setName($filename);
         $doc->setFile($upfile);
         $dm->persist($doc);
         $dm->flush();
         $fileid = $doc->getId();
         $fileid_small = "";
         $fileid_middle = "";
         if ($isimage) {
             $im = new \Imagick($upfile);
             if ($im->getImageWidth() > 100) {
                 if ($im->getImageWidth() >= $im->getImageHeight()) {
                     $im->scaleImage(100, 0);
                 } else {
                     $im->scaleImage(0, 100);
                 }
                 $im->writeImage($imagefilepath_small);
                 $im->destroy();
             } else {
                 copy($upfile, $imagefilepath_small);
             }
             $im = new \Imagick($upfile);
             if ($im->getImageWidth() > 400) {
                 $im->scaleImage(400, 0);
                 $im->writeImage($imagefilepath_middle);
                 $im->destroy();
             } else {
                 copy($upfile, $imagefilepath_middle);
             }
             $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
             $doc->setName($imagefilename_small);
             $doc->setFile($imagefilepath_small);
             $dm->persist($doc);
             $dm->flush();
             $fileid_small = $doc->getId();
             unlink($imagefilepath_small);
             $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
             $doc->setName($imagefilename_middle);
             $doc->setFile($imagefilepath_middle);
             $dm->persist($doc);
             $dm->flush();
             $fileid_middle = $doc->getId();
             unlink($imagefilepath_middle);
         }
         unlink($upfile);
         //д��ݿ⣺we_files
         $da = $this->get("we_data_access");
         $fixs = explode(".", strtolower($filename));
         $sqls = array();
         $all_params = array();
         $sqls[] = "insert into we_files(`circle_id`,`file_ext`,`file_id`,`file_name`,`post_to_group`,`up_by_staff`,`up_date`)values(?,?,?,?,?,?,now())";
         $all_params[] = array((string) $circle_id, (string) $fixs[count($fixs) - 1], (string) $fileid, (string) $filename, (string) $group_id, (string) $user->getUsername());
         if ($isimage) {
             $sqls[] = "insert into we_files_image(file_id, file_id_small, file_id_middle) values(?, ?, ?)";
             $all_params[] = array((string) $fileid, (string) $fileid_small, (string) $fileid_middle);
         }
         $da->ExecSQLs($sqls, $all_params);
         $re["returncode"] = ReturnCode::$SUCCESS;
         $re["file_id"] = $fileid;
     } catch (\Exception $e) {
         $re["returncode"] = ReturnCode::$SYSERROR;
         $this->get('logger')->err($e);
     }
     $response = new Response($request->get('jsoncallback') ? $request->get('jsoncallback') . "(" . json_encode($re) . ");" : json_encode($re));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Ejemplo n.º 7
0
 private function getFileId($upfile, $maxwidth = 2100, $maxheight = 1600)
 {
     $fileid = '';
     if (empty($upfile)) {
         return '';
     }
     $isimage = preg_match(\Justsy\BaseBundle\Common\MIME::getMIMEImgReg(), strtolower($upfile->getClientOriginalName()));
     if ($isimage) {
         if ($maxwidth > 0 && $maxheight > 0) {
             $im = new \Imagick($upfile->getPathname());
             if (!empty($maxwidth) && $im->getImageWidth() > $maxwidth) {
                 unlink($upfile->getPathname());
                 return '';
             }
             if (!empty($maxheight) && $im->getImageHeight() > $maxheight) {
                 unlink($upfile->getPathname());
                 return '';
             }
         }
         //开始上传图片
         $dm = $this->get('doctrine.odm.mongodb.document_manager');
         $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
         $filename = $upfile->getClientOriginalName();
         $doc->setName($filename);
         $doc->setFile($upfile->getPathname());
         $dm->persist($doc);
         $dm->flush();
         $fileid = $doc->getId();
     }
     unlink($upfile->getPathname());
     return $fileid;
 }
Ejemplo n.º 8
0
     } else {
         $result = array("exist" => "0");
     }
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
 //判断群组是否已经存在
 public function checkAction(Request $request)
 {
     $groupName = $request->get('txtname');
     $da = $this->get("we_data_access");
     $result;
     $table = $da->GetData("group", "select group_id from we_groups where group_name=?", array((string) $groupName));
     if ($table && $table["group"]["recordcount"] > 0) {
         $result = array('exist' => 1);
     } else {
         $result = array('exist' => 0);
     }
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
 //添加或修改群组信息
 public function updateAction()
 {
     $request = $this->get("request");
     $groupid = $request->get("id");
     $groupid = $groupid == null ? 0 : (int) $groupid;
     $da = $this->get("we_data_access");
     $da_im = $this->get("we_data_access_im");
     $upfile = $request->files->get("file_upload");
     $fileid = "";
     //判断是添加还是修改
     $table = $da->GetData("group", "select group_id from we_groups where group_id=?", array((string) $groupid));
     if ($table && $table["group"]["recordcount"] == 0) {
         $groupid = 0;
     }
     //groupid=0表示添加群组管理
     if ($upfile != null) {
         $dm = $this->get('doctrine.odm.mongodb.document_manager');
         if ($groupid > 0) {
             $table = $da->GetData("group", "select group_photo_path from we_groups where group_id=?", array((string) $groupid));
             if ($table && $table["group"]["recordcount"] > 0) {
                 $img = $table["group"]["rows"][0]["group_photo_path"];
                 if ($img != null && $img != "") {
                     $doc = $dm->getRepository('JustsyMongoDocBundle:WeDocument')->find($img);
                     $dm->remove($doc);
                     $dm->flush();
                 }
             }
         }
         $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
         $doc->setName($upfile->getClientOriginalName());
         $doc->setFile($upfile->getPathname());
         $dm->persist($doc);
         $dm->flush();
         $fileid = $doc->getId();
         unlink($upfile->getPathname());
     }
     //对数据的操作
     $sqls = "";
     $paras = "";
     $sqls_im = "";
     $paras_im = "";
Ejemplo n.º 9
0
 public function uploadfileAction()
 {
     $re = array('s' => '1', 'm' => '', "fileid" => '', "filename" => '');
     $fileElementName = "file";
     if (!empty($_FILES[$fileElementName]['error'])) {
         switch ($_FILES[$fileElementName]['error']) {
             case '1':
                 $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
                 break;
             case '2':
                 $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
                 break;
             case '3':
                 $error = 'The uploaded file was only partially uploaded';
                 break;
             case '4':
                 $error = 'No file was uploaded.';
                 break;
             case '6':
                 $error = 'Missing a temporary folder';
                 break;
             case '7':
                 $error = 'Failed to write file to disk';
                 break;
             case '8':
                 $error = 'File upload stopped by extension';
                 break;
             case '999':
             default:
                 $error = 'No error code avaiable';
         }
     } else {
         if (empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none') {
             $error = 'No file was uploaded..';
         } else {
             try {
                 $filename = $_FILES[$fileElementName]['name'];
                 $filesize = $_FILES[$fileElementName]['size'];
                 $filetemp = $_FILES[$fileElementName]['tmp_name'];
                 $dm = $this->get('doctrine.odm.mongodb.document_manager');
                 $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
                 $doc->setName($filename);
                 $doc->setFile($filetemp);
                 $dm->persist($doc);
                 $dm->flush();
                 $fileid = $doc->getId();
                 @unlink($filetemp);
                 if (empty($fileid)) {
                     $re['s'] = '0';
                     $re['msg'] = '文件上传失败';
                 } else {
                     $re['fileid'] = $fileid;
                     $re['filename'] = $filename;
                 }
             } catch (\Exception $e) {
             }
         }
     }
     $result = array("error" => $error, "msg" => $re['msg'], "s" => $re["s"], "fileid" => $re['fileid'], "filename" => $re['filename']);
     $response = new Response(json_encode($result));
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Ejemplo n.º 10
0
 protected function saveCertificate($filetemp, $filename)
 {
     try {
         $upfile = tempnam(sys_get_temp_dir(), "we");
         unlink($upfile);
         /*
         $somecontent1 = base64_decode($filedata);
         if ($handle = fopen($upfile, "w+")) {   
           if (!fwrite($handle, $somecontent1) == FALSE) {   
             fclose($handle);  
           }  
         }
         */
         if (move_uploaded_file($filetemp, $upfile)) {
             $dm = $this->get('doctrine.odm.mongodb.document_manager');
             $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
             $doc->setName($filename);
             $doc->setFile($upfile);
             $dm->persist($doc);
             $dm->flush();
             $fileid = $doc->getId();
             return $fileid;
         } else {
             return "";
         }
     } catch (\Exception $e) {
         $this->get('logger')->err($e);
         return "";
     }
 }
Ejemplo n.º 11
0
 public function savenewdocAction($network_domain)
 {
     //
     $request = $this->get("request");
     $name = $request->get("newdoc_name");
     $newdoc_parent_dir = $request->get("newdoc_parent_dir");
     $user = $this->get('security.context')->getToken()->getUser();
     $login_account = $user->getUserName();
     $circleId = $user->get_circle_id($network_domain);
     if (empty($newdoc_parent_dir)) {
         $newdoc_parent_dir = "c" . $circleId;
     }
     $firstChar = substr($newdoc_parent_dir, 0, 1);
     if ($firstChar == "g") {
         $gorupid = substr($newdoc_parent_dir, 1);
     } else {
         $gorupid = "ALL";
     }
     $name = $name . ".html";
     $path = "/tmp/" . $name;
     $txt = $request->get("newdoc_content");
     $txt = iconv("utf-8", "gbk", $txt);
     $fp = fopen($path, "w+");
     $v = "0";
     flock($fp, LOCK_EX);
     if (fwrite($fp, $txt)) {
         flock($fp, LOCK_UN);
         fclose($fp);
         $dm = $this->get('doctrine.odm.mongodb.document_manager');
         $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
         $doc->setName($name);
         $doc->setFile($path);
         $dm->persist($doc);
         $dm->flush();
         $fileid = $doc->getId();
         unlink($path);
         $sql = "insert into we_files(`circle_id`,`file_ext`,`file_id`,`file_name`,`post_to_group`,`up_by_staff`,`up_date`,`dir`)values(?,?,?,?,?,?,now(),?)";
         $all_params = array((string) $circleId, "html", (string) $fileid, (string) $name, (string) $gorupid, (string) $login_account, (string) $newdoc_parent_dir);
         $da = $this->get('we_data_access');
         $da->ExecSQL($sql, $all_params);
         //当上传到圈子/群组目录时,默认共享到该圈子/群组中
         if ($firstChar == 'c' || $firstChar == 'g') {
             $this->saveShare($fileid, "1", substr($newdoc_parent_dir, 1), $firstChar, 'r');
         }
         $response = new Response(json_encode(array("succeed" => 1, "fileid" => $fileid)));
     } else {
         $response = new Response(json_encode(array("succeed" => 0)));
     }
     $response->headers->set('Content-Type', 'text/json');
     return $response;
 }
Ejemplo n.º 12
0
 public function updatePortalIconAction()
 {
     $da = $this->get("we_data_access");
     $user = $this->get('security.context')->getToken()->getUser();
     $eno = $user->eno;
     $username = $user->getUsername();
     $request = $this->getRequest();
     $logo = $request->get("fileid");
     $crop = $request->get("crop");
     if (!empty($crop)) {
         $crop = json_decode($crop, true);
     }
     $appid = $request->get("appid");
     $success = true;
     $newfileid = "";
     if (!empty($logo) && !empty($crop)) {
         //源图像另存为
         $doc = $this->get('doctrine.odm.mongodb.document_manager')->getRepository('JustsyMongoDocBundle:WeDocument')->find($logo);
         if (!empty($doc)) {
             $filename1 = strtolower($doc->getName());
             $expname = explode(".", $filename1);
             $expname = $expname[1];
             $src = tempnam(sys_get_temp_dir(), "tmp") . "." . $expname;
             $file = $doc->getFile();
             $filename2 = $file->getFilename();
             $tybes = $file->getBytes();
             $cont = fopen($src, 'w');
             fwrite($cont, $tybes);
             fclose($cont);
             $gd = new \Justsy\AppCenterBundle\Common\Gd();
             $gd->open($src);
             if ($gd->is_image()) {
                 $gd->crop((int) $crop["x"], (int) $crop["y"], (int) $crop["w"], (int) $crop["h"]);
                 $gd->resize_to(180, 180, 'force');
                 $gd->save_to($src);
                 $dm = $this->get('doctrine.odm.mongodb.document_manager');
                 $doc = new \Justsy\MongoDocBundle\Document\WeDocument();
                 $doc->setName(basename($src));
                 $doc->setFile($src);
                 $dm->persist($doc);
                 $dm->flush();
                 $newfileid = $doc->getId();
             }
             unlink($src);
             //数据记录操作处理
             $sql = "update we_apps_portalconfig set logo=? where appid=?";
             $params = array((string) $newfileid, $appid);
             //删除原来的文件
             $dm = $this->get('doctrine.odm.mongodb.document_manager');
             Utils::removeFile($logo, $dm);
             try {
                 $da->ExecSQL($sql, $params);
             } catch (\Exception $e) {
                 $success = false;
                 $this->get("logger")->err($e->getMessage());
             }
         }
     }
     $re = array("success" => $success, "fileid" => $newfileid);
     $result = new Response(json_encode($re));
     $result->headers->set('Content-Type', 'text/json');
     return $result;
 }