uploadfile图片上传和ashx

 

uploadify.swf需要是支持中文

 $(function () {
 //获取所有上传按钮id
 $("div[id^='fileInput_']").each(function () {
 var name = $(this).attr("id");
 create(name);
 });
 });
  
 function create(name) {
 var select = "上传图片";
 if (name.indexOf("_") > -1) {
 if (name.substring(name.lastIndexOf("_") + 1) == "1") {
 var select = "大图";
 }
 else if (name.substring(name.lastIndexOf("_") + 1) == "2") {
 select = "小图";
 }
 }
 $('#' + name).uploadify({
 'uploader': '/uploadify/uploadify.swf',
 'script': 'Pro_Sub.aspx?upfile=1',
 'cancelImg': '/uploadify/cancel.png',
 'folder': '/ProductImg/',
 'fileExt': '*.jpg;*.gif;*.png;*.bmp;*.JPEG;',
 'fileDesc': '请选择 *.jpg;*.gif;*.png,*.bmp;*.JPEG 格式的图片',
 'multi': true,
 'auto': true,
 'buttonText':select,
 'onComplete': function (event, queueId, fileObj, response, data) {
 var re = response.split('|@|');
 if (re[0] == "1") {
 var box = name.substring(10);
 var html = "<div class='ImgHtml' OnClick='change(this)'><input class='input2' style='display: none;' type='button' value='删&nbsp&nbsp&nbsp除' οnclick='delImg(this);showfi("+name.replace("_",".")+");' /><input type='checkbox' checked='checked' class='hide' value='" + re[1] + "' /><img class='Img' src='" + re[1] + "'></div>";
 if (box == "1_0") {
 $("#ContentPlaceHolder1_rpAttribute_txtvalue_4").val(re[1]);
 html = "<div class='ImgHtml' OnClick='change(this)'><input class='input2' style='display: none;' type='button' value='删&nbsp&nbsp&nbsp除' οnclick='delImg(this);showfi(1)' /><input type='checkbox' class='hide' value='" + re[1] + "' /><img class='Img' src='" + re[1] + "'></div>";
 $("#file0").hide();
 }
  
 $(".box" + box).append(html);
  
 } else {
 ymPrompt.errorInfo({ message: "上传失败!", showMask: true });
 }
 }
 });
 }
  
 

</script>

 

 

=============================================================================

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

using System.Web.SessionState;
using UI;

namespace Admin.TkAdmin.Product
{
/// <summary>
/// imgsave 的摘要说明
/// </summary>
public class imgsave : IHttpHandler,IReadOnlySessionState
{
public HttpRequest Request;
public HttpResponse Response;
public HttpSessionState Session;
public void ProcessRequest(HttpContext context)
{

context.Response.ContentType = "text/plain";
Response = context.Response;
Request = context.Request;
Session = context.Session;

string upfile = Request["upfile"];
if (upfile != "")
{
//如果值为1zhi
if (upfile == "1")
{
uploadfile();
}
}

}

//对上传的图片进行保存到指定文件中
private void uploadfile()
{
HttpPostedFile file = Request.Files["Filedata"];
string UploadFile = "";
HttpContext.Current.Server.MapPath(@Request["folder"]);
string newFileName = "";
if (file != null)
{
Isfile(UploadFile);
try {
//创建随机种子
Random ra;
if (Session["IntIndexImg"] != null)
{
ra = new Random(Convert.ToInt32(Session["IntIndexImg"]));
}
else
{
ra = new Random();
}

int rInt = ra.Next(1000);

Session["IntIndexImg"] = rInt;

newFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + rInt + Path.GetExtension(file.FileName).ToUpper();
string BigimageURL = (FileUrl.ProductBigImgUrl + newFileName).Replace('\\', '/');
Isfile(FileUrl.ProductBigImgUrl);
file.SaveAs(BigimageURL);
//保存缩列图
string SmallimgeURL = (FileUrl.ProductSmallImgUrl + newFileName).Replace('\\', '/');
Isfile(FileUrl.ProductSmallImgUrl);
CreateSmallPic.CreateImageOutput(120, 60, BigimageURL, SmallimgeURL);
Response.Write("1|@|" + FileUrl.ProductSmallImgUrl1 + newFileName);

}catch
{
Response.Write("0");
}
}
}

//用于创建目录
private void Isfile(string UploadFile)
{
if (!Directory.Exists(UploadFile))
{
Directory.CreateDirectory(UploadFile);
}

}

public bool IsReusable
{
get
{
return false;
}
}
}
}

转载于:https://www.cnblogs.com/liwp/p/5943254.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值