C#_Fileuploadify_notMvc
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="jqUploadify._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<link href="scripts/uploadify.css" rel="stylesheet" type="text/css" />
<link href="scripts/default.css" rel="stylesheet" type="text/css" /> <script src="scripts/jquery-1.7.2.min.js" type="text/javascript"></script> <script src="scripts/swfobject.js" type="text/javascript"></script> <script src="scripts/jquery.uploadify.min.js" type="text/javascript"></script> <script type="text/javascript">
$(function(){
$("#file_upload").uploadify({
//开启调试
'debug' : false,
//是否自动上传
'auto':false,
'buttonText':'选择照片',
//flash
'swf': "scripts/uploadify.swf",
//文件选择后的容器ID
'queueID':'uploadfileQueue',
'uploader':'scripts/upload.ashx',
'width':'',
'height':'',
'multi':false,
'fileTypeDesc':'支持的格式:',
'fileTypeExts':'*.jpg;*.jpge;*.gif;*.png',
'fileSizeLimit':'1MB',
'removeTimeout':, //返回一个错误,选择文件的时候触发
'onSelectError':function(file, errorCode, errorMsg){
switch(errorCode) {
case -:
alert("上传的文件数量已经超出系统限制的"+$('#file_upload').uploadify('settings','queueSizeLimit')+"个文件!");
break;
case -:
alert("文件 ["+file.name+"] 大小超出系统限制的"+$('#file_upload').uploadify('settings','fileSizeLimit')+"大小!");
break;
case -:
alert("文件 ["+file.name+"] 大小异常!");
break;
case -:
alert("文件 ["+file.name+"] 类型不正确!");
break;
}
},
//检测FLASH失败调用
'onFallback':function(){
alert("您未安装FLASH控件,无法上传图片!请安装FLASH控件后再试。");
},
//上传到服务器,服务器返回相应信息到data里
'onUploadSuccess':function(file, data, response){
//alert(data);
}
});
}); function doUplaod(){
$('#file_upload').uploadify('upload','*');
} function closeLoad(){
$('#file_upload').uploadify('cancel','*');
} </script> </head>
<body>
<table width="" border="" align="center" cellpadding="" cellspacing="" id="__01">
<tr>
<td align="center" valign="middle">
<div id="uploadfileQueue" style="padding: 3px;">
</div>
<div id="file_upload">
</div>
</td>
</tr>
<tr>
<td height="" align="center" valign="middle">
<img alt="" src="data:images/BeginUpload.gif" width="" height="" onclick="doUplaod()" style="cursor: hand" />
<img alt="" src="data:images/CancelUpload.gif" width="" height="" onclick="closeLoad()" style="cursor: hand" />
</td>
</tr>
</table>
</body>
</html>
using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.SessionState;
using System.IO; namespace jqUploadify.scripts
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class upload : IHttpHandler, IRequiresSessionState
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Charset = "utf-8"; HttpPostedFile file = context.Request.Files["Filedata"];
string uploadPath = context.Server.MapPath("..\\uploads\\"); if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
file.SaveAs(uploadPath + file.FileName);
//生成缩略图
MakeThumbnail(uploadPath + file.FileName, uploadPath + "\\s\\" + file.FileName, , );
}
} private void MakeThumbnail(string sourcePath, string newPath, int width, int height)
{
System.Drawing.Image ig = System.Drawing.Image.FromFile(sourcePath);
int towidth = width;
int toheight = height;
int x = ;
int y = ;
int ow = ig.Width;
int oh = ig.Height;
if ((double)ig.Width / (double)ig.Height > (double)towidth / (double)toheight)
{
oh = ig.Height;
ow = ig.Height * towidth / toheight;
y = ;
x = (ig.Width - ow) / ; }
else
{
ow = ig.Width;
oh = ig.Width * height / towidth;
x = ;
y = (ig.Height - oh) / ;
}
System.Drawing.Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Clear(System.Drawing.Color.Transparent);
g.DrawImage(ig, new System.Drawing.Rectangle(, , towidth, toheight), new System.Drawing.Rectangle(x, y, ow, oh), System.Drawing.GraphicsUnit.Pixel);
try
{
bitmap.Save(newPath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
throw ex;
}
finally
{
ig.Dispose();
bitmap.Dispose();
g.Dispose();
} } public bool IsReusable
{
get
{
return false;
}
}
}
}
C#_Fileuploadify_notMvc的更多相关文章
随机推荐
- 使用libzplay库封装一个音频类
装载请说明原地址,谢谢~~ 前两天我已经封装好一个duilib中使用的webkit内核的浏览器控件和一个基于vlc的用于播放视频的视频控件,这两个控件可以分别用在放酷狗播放器的乐库功能和MV ...
- PHP Module中获取$_GET/$_POST/$_COOKIE的方法研究
假设要获取$_GET['c']; 首先,先介绍下http_globals; 1.http_globals,定义在php_globals.h中: zval * http_globals[6]; 其中的索 ...
- JDBC第一天连接池案例
JDBC,JDBC的工具类JDBC 连接从连接池中拿: 创建连接池的语句: package day01; import java.sql.Connection; import java.sql.Dri ...
- 对Struts的理解
1.struts是一个按MVC模式设计的Web层框架,其实他就是一个大大的servlet,这个Servlet名为ActionServlet,或是ActionServlet的子类.我们可以在web.xm ...
- HDU 1707
思路:标记课程表上的课程,询问时遍历课程表,再以字典序输出名字. #include<iostream> #include<stdio.h> #include<stdlib ...
- Tkinter教程之Text篇(3)
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811348 '''Tkinter教程之Text篇(3)''''''14.自定义tag的两个内置 ...
- linux - 怎么自动填写有交互的shell脚本 - SegmentFault
linux - 怎么自动填写有交互的shell脚本 - SegmentFault TCL/Expect交互式自动化测试概要 - - ITeye技术网站 expect是一种基于TCL,能与交互式程序进行 ...
- homework-05
经过这几天的深思熟虑我和小明同学将这次作业基本的完整了,可能界面略丑陋,但是基本功能均已实现.我们的服务器端采用python编写,因为服务器端是这次作业的难点,而python中有一个叫做web.py的 ...
- picture to string
图片转化为字符原理: 一张m*n大小的图片,实际上可以看成是一个m*n的矩阵.矩阵的每一个元素就是一个Color值,不同的Color值,用不同的Ascii可以在屏幕上打印显示的字符来代替,于是可以得到 ...
- Cannot retrieve metalink for repository: epel. Please verify its path and try again
今天在测试环境使用yum安装,遇到一个问题: Error: Cannot retrieve metalink for repository: epel. Please verify its path ...