Exemplo n.º 1
0
        public JsonResult UploadPicture()
        {
            ViewModel.BaseJsonData json = new ViewModel.BaseJsonData();
            var file = Request.Files["data"];

            if (file == null)
            {
                json.state    = 0;
                json.msg_text = "没有文件,请重新上传。";
            }
            if (Path.GetExtension(file.FileName).ToLower() != ".jpg")
            {
                json.state    = 0;
                json.msg_text = "请上传jpg格式文件。";
            }
            string file_name      = string.Format("{0}.jpg", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
            string file_name_temp = string.Format("{0}_temp.jpg", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
            string save_path      = Server.MapPath(string.Format("~/images/temp/{0}", file_name));
            string save_path_temp = Server.MapPath(string.Format("~/images/temp/{0}", file_name_temp));

            file.SaveAs(save_path);
            ImageFun.MakeThumbnail(save_path, save_path_temp, 160, 0, "W");
            json.state = 1;
            json.data  = file_name_temp;
            return(Json(json));
        }
        public JsonResult FileUpload()
        {
            ViewModel.BaseJsonData json = new ViewModel.BaseJsonData();
            var file = Request.Files["data"];

            if (file == null)
            {
                json.state    = 0;
                json.msg_text = "没有文件,请重新上传。";
            }
            if (!extension.Contains(io.Path.GetExtension(file.FileName).ToLower()))
            {
                json.state    = 0;
                json.msg_text = "上传文件不在允许的格式范围内。";
            }
            string dtStr   = DateTime.Now.ToString("yyyyMMdd");
            string TempDir = string.Format("{0}{1}\\", attachmentTempPath, dtStr);

            if (!io.Directory.Exists(TempDir))
            {
                io.Directory.CreateDirectory(TempDir);
            }
            string file_name = string.Format("{0}{1}", TempDir, file.FileName);
            string temp_file = SetSameName(file_name);

            file.SaveAs(temp_file);
            string fileName = io.Path.GetFileName(temp_file);

            json.state = 1;
            json.data  = string.Format("{0}/{1},{2}\\{3},{4}", dtStr, fileName, dtStr, fileName, fileName);
            return(Json(json));
        }
Exemplo n.º 3
0
        public JsonResult UploadPicture()
        {
            ViewModel.BaseJsonData json = new ViewModel.BaseJsonData();
            var file = Request.Files["data"];

            if (file == null)
            {
                json.state    = 0;
                json.msg_text = "没有文件,请重新上传。";
            }
            if (Path.GetExtension(file.FileName).ToLower() != ".jpg")
            {
                json.state    = 0;
                json.msg_text = "请上传jpg格式文件。";
            }
            string photoTempDir = MyConfiguration.GetTempPhotoPath();

            if (!Directory.Exists(photoTempDir))
            {
                Directory.CreateDirectory(photoTempDir);
            }
            string guid           = Guid.NewGuid().ToString("N");
            string file_name      = string.Format("{0}{1}.jpg", photoTempDir, guid);
            string file_name_temp = string.Format("{0}{1}_temp.jpg", photoTempDir, guid);

            file.SaveAs(file_name);
            ImageFun.MakeThumbnail(file_name, file_name_temp, 106, 0, "W");
            json.state = 1;
            json.data  = Path.GetFileName(file_name_temp);
            return(Json(json));
        }