图片上传
2021-05-17 19:28
标签:success stop session 插件 path element reverse query tom 一,效果 二,材料 css 图片 javascript ");
$p.html(fileList[i].name).appendTo($section);
//var $input = $("");
// $input.appendTo($section);
//var $input2 = $("");
// $input2.appendTo($section);
}
}
setTimeout(function(){
$(".up-section").removeClass("loading");
$(".up-img").removeClass("up-opcity");
},450);
numUp = imgContainer.find(".up-section").length;
if(numUp >= 5){
$(this).parent().hide();
}
//input内容清空
$(this).val("");
});
$(".z_photo").delegate(".close-upimg", "click", function () {
// alert(1);
$(".works-mask").show();
delParent = $(this).parent();
});
$(".wsdel-ok").click(function () {
// alert(2);
$(".works-mask").hide();
var numUp = delParent.siblings().length;
if(numUp ){
delParent.parent().find( 后端C# 图片上传 标签:success stop session 插件 path element reverse query tom 原文地址:http://www.cnblogs.com/mlfg/p/7742465.html
HTMLdiv class="panel panel-primary">
div class="panel-heading">
h3 class="panel-title">图片:h3>
div>
div class="panel-body">
div class="img-box full">
section class="img-section">
p class="up-p">span class="up-span">最多可以上传5张图片,马上上传。span>p>
div class="z_photo upimg-div clear">
@if (Model.Item1 != null && Model.Item1.Images != null)
{
foreach (var path in Model.Item1.Images)
{
section class="up-section fl" id="img_@path.Item1">
span class="up-span">span>
img src="/Scripts/imgup/a7.png" class="close-upimg">
@*img src="/img/buyerCenter/3c.png" class="type-upimg" alt="添加标签">*@
img src="@path.Item2" class="up-img">
p class="img-namep">p>
@*input id="taglocation" name="taglocation" value="" type="hidden">
input id="tags" name="tags" value="" type="hidden">*@
section>
}
}
section class="z_file fl">
img src="~/Scripts/imgup/a11.png" class="add-img" />
@*img src="a_data/a11.png" class="add-img">*@
input name="file" id="file" class="file" value="" accept="image/jpg,image/jpeg,image/png,image/bmp" multiple="" type="file">
section>
div>
section>
div>
aside class="mask works-mask">
div class="mask-content">
p class="del-p">您确定要删除作品图片吗?p>
p class="check-p">span class="del-com wsdel-ok">确定span>span class="wsdel-no">取消span>p>
div>
aside>
@*input id="uploadFile" name="uploadFile" type="file" class="file" multiple data-preview-file-type="any">
@if (Model.Item1.Images != null){
foreach (string path in Model.Item1.Images)
{
input type="hidden" class="oldimage" name="oldimage" value="@path">
}
}*@
div>
div>
/*上传图片插件的样式*/
.img-box{
margin-top: 40px;
}
.img-box .up-p{
margin-bottom: 20px;
font-size: 16px;
color: #555;
}
.z_photo{
padding: 18px;
border:2px dashed #E7E6E6;
/*padding: 18px;*/
}
.z_photo .z_file{
position: relative;
}
.z_file .file{
width: 100%;
height: 100%;
opacity: 0;
position: absolute;
top: 0px;
left: 0px;
z-index: 100;
}
.z_photo .up-section{
position: relative;
margin-right: 20px;
margin-bottom: 20px;
}
.up-section .close-upimg{
position: absolute;
top: 6px;
right: 8px;
display: none;
z-index: 10;
}
.up-section .up-span{
display: block;
width: 100%;
height: 100%;
visibility: hidden;
position: absolute;
top: 0px;
left: 0px;
z-index: 9;
background: rgba(0,0,0,.5);
}
.up-section:hover{
border: 2px solid #f15134;
}
.up-section:hover .close-upimg{
display: block;
}
.up-section:hover .up-span{
visibility: visible;
}
.z_photo .up-img{
display: block;
width: 100%;
height: 100%;
}
.loading{
border: 1px solid #D1D1D1;
background:url(/Scripts/imgup/loading.gif) no-repeat center;
}
.up-opcity{
opacity: 0;
}
.img-name-p{
display: none;
}
.upimg-div .up-section {
width: 190px;
height: 180px;
}
.img-box .upimg-div .z_file {
width: 190px;
height: 180px;
}
.z_file .add-img {
display: block;
width: 190px;
height: 180px;
}
/*遮罩层样式*/
.mask{
z-index: 1000;
display: none;
position: fixed;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background: rgba(0,0,0,.4);
}
.mask .mask-content{
width: 500px;
position: absolute;
top: 50%;
left: 50%;
margin-left: -250px;
margin-top: -80px;
background: white;
height: 160px;
text-align: center;
}
.mask .mask-content .del-p{
color: #555;
height: 94px;
line-height: 94px;
font-size: 18px;
border-bottom: 1px solid #D1D1D1;
}
.mask-content .check-p{
height: 66px;
line-height: 66px;
position: absolute;
bottom: 0px;
left: 0px;
width: 100%;
}
.mask-content .check-p span{
width: 49%;
display:inline-block;
text-align: center;
color:#d4361d ;
font-size: 18px;
}
.check-p .del-com{
border-right: 1px solid #D1D1D1;
}
$(function(){
var delParent;
var defaults = {
fileType : ["jpg","png","bmp","jpeg"], // 上传文件的类型
fileSize : 1024 * 1024 * 10 // 上传文件的大小 10M
};
/*点击图片的文本框*/
$(".file").change(function(){
var idFile = $(this).attr("id");
var file = document.getElementById(idFile);
var imgContainer = $(this).parents(".z_photo"); //存放图片的父亲元素
var fileList = file.files; //获取的图片文件
console.log(fileList+"======filelist=====");
var input = $(this).parent();//文本框的父亲元素
var imgArr = [];
//遍历得到的图片文件
var numUp = imgContainer.find(".up-section").length;
var totalNum = numUp + fileList.length; //总的数量
if(fileList.length > 5 || totalNum > 5 ){
alert("上传图片数目不可以超过5个,请重新选择"); //一次选择上传超过5个 或者是已经上传和这次上传的到的总数也不可以超过5个
}
else if(numUp ){
fileList = validateUp(fileList);
for(var i = 0;i
[HttpPost]
public ActionResult FileInput()
{
try
{
var files = Request.Files;
if (files != null && files.Count > 0)
{
Listint> imagesid = new Listint>();
if (Session["GoodImages"] != null)
{
imagesid = (Listint>)Session["GoodImages"];
}
int i = 0;
var file = files[i];
string fileName = file.FileName;
string fileRelName = Request["uuid"]; //fileName.Substring(0, fileName.LastIndexOf(‘.‘));//设置临时存放文件夹名称
string index = Guid.NewGuid().ToString(); // Convert.ToInt32(Request["chunk"]);//当前分块序号
// var guid = Request["guid"];//前端传来的GUID号
var dir = Server.MapPath("~/Upload");//文件上传目录
dir = Path.Combine(dir, fileRelName);//临时保存分块的目录
if (!System.IO.Directory.Exists(dir))
System.IO.Directory.CreateDirectory(dir);
string filePath = Path.Combine(dir, index.ToString() + fileName.Substring(fileName.LastIndexOf(‘.‘)));//分块文件名为索引名,更严谨一些可以加上是否存在的判断,防止多线程时并发冲突
var data = file;//表单中取得分块文件
//if (data != null)//为null可能是暂停的那一瞬间
//{
data.SaveAs(filePath);//报错
//}
GoodImages gi = new GoodImages();
gi.ImagePath = filePath;
gi.Name = fileName;
GoodImagesService.Insert