教教我这个功能怎么用asp实现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了教教我这个功能怎么用asp实现相关的知识,希望对你有一定的参考价值。
就是页面上显示一个文件上传的控件,
当用户选择好文件并点击上传按钮以后
隐藏上传文件的这个窗体,打开一个隐藏的窗体,显示“文件正在上传中”
应该怎么做
<%@LANGUAGE="VBSCRIPT" CODEPAGE="CP_ACP"%>
<html>
<head>
<title>上传图片</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<Script language="javascript">
function mysubmit(theform)
if(theform.big.value=="")
alert("请点击浏览按钮,选择您要上传的jpg或gif文件!")
theform.big.focus;
return (false);
else
str= theform.big.value;
strs=str.toLowerCase();
lens=strs.length;
extname=strs.substring(lens-4,lens);
if(extname!=".jpg" && extname!=".gif")
alert("请选择jpg或gif文件!");
return (false);
return (true);
</script>
<body background="../skin/shishuiliu/back.gif" style="background-attachment: fixed" bgcolor="#B3B3B3">
<form action="up.asp" method="post" enctype="multipart/form-data" name="form" onsubmit="return mysubmit(this)>
<p align="center">
<div align="center">
<input type="file" name="file"></p>
</div>
<p align="center">
<input type="submit" name="Submit" value="上传...">
<a href="show.asp"><font size="2">显示图片</font></a> </p>
</form>
</body>
</html>
UP.ASP
<%option explicit%>
<%
dim conn,DBPath
dim rs,sql
Set conn = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("db.mdb")
conn.Open "driver=Microsoft Access Driver (*.mdb);dbq=" & DBPath
set rs=server.CreateObject("ADODB.Recordset")
sql="select * from photo"
rs.open sql,conn,3,2
dim formsize,formdata,bncrlf,divider,datastart,dataend,mydata
formsize=request.totalbytes
formdata=request.binaryread(formsize)
bncrlf=chrB(13) & chrB(10)
divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
mydata=midb(formdata,datastart,dataend)
rs.addnew
rs("img").appendchunk=mydata
rs.update
rs.close
'释放对象以及重新定向到main.html页面
set rs=nothing
set conn=nothing
response.Redirect("main.html")
%>
还要有一个DB数据库
C#实现二维码功能,winform 以及 asp.net均可以用
二维码现在用途很多,怎么用C#编程生成呢?
准备 ThoughtWorks.QRCode.dll
需要 一个类 QRCode,这个类专门来生成二维码的
using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using ThoughtWorks.QRCode; using ThoughtWorks.QRCode.Codec; namespace QRCodePro { public class QRCode { /// 生成二维码 /// </summary> /// <param name="strData">要生成的文字或者数字</param> /// <param name="qrEncoding">三种尺寸:BYTE ,ALPHA_NUMERIC,NUMERIC</param> /// <param name="level">大小:L M Q H</param> /// <param name="version">版本:如 8</param> /// <param name="scale">比例:如 4</param> /// <returns></returns> public static Image CreateCode_Choose(string strData, string qrEncoding, string size, int version, int scale) { QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); string encoding = qrEncoding; switch (encoding) { case "Byte": qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; break; case "AlphaNumeric": qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC; break; case "Numeric": qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC; break; default: qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; break; } qrCodeEncoder.QRCodeScale = scale; qrCodeEncoder.QRCodeVersion = version; switch (size) { case "L": qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L; break; case "M": qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; break; case "Q": qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q; break; default: qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H; break; } //文字生成图片 Image image = qrCodeEncoder.Encode(strData); return image; } } }
在vs中新建窗体,搭建窗体,如图所示:
在主窗体中需要的代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace QRCodePro { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { cboEncoding.Items.Add("Byte"); cboEncoding.Items.Add("AlphaNumeric"); cboEncoding.Items.Add("Numeric"); cboEncoding.SelectedIndex = 0; //填充大小下拉框 cboSize.Items.Add("M"); cboSize.Items.Add("L"); cboSize.Items.Add("Q"); cboSize.Items.Add("H"); cboSize.SelectedIndex = 0; //填充文本框 txtVersion.Text = "8"; txtScale.Text = "4"; } private void btnCreateCode_Click(object sender, EventArgs e) { string content = txtContent.Text; int version = Convert.ToInt32(txtVersion.Text); int scale = Convert.ToInt32(txtScale.Text); string size = cboSize.SelectedItem.ToString(); string encoding = cboEncoding.SelectedItem.ToString(); //检查空值字符串 if (content == null || content == "") { MessageBox.Show("请输入二维码信息,支持中文"); } else { Image img = QRCode.CreateCode_Choose(content, encoding, size, version, scale); picCode.Image = img; } } private void btnReset_Click(object sender, EventArgs e) { txtContent.Text = ""; } private void btnSave_Click(object sender, EventArgs e) { if (picCode.Image != null) { SaveImages(picCode); } else { MessageBox.Show("还没生成图像呢!"); } } private void SaveImages(PictureBox pic) { string Parentpath = @"D:\\Photo"; //自1970 年1月1日00:00:00 GMT以来的毫秒数 string filename = DateTime.Now.Ticks.ToString(); if (Parentpath.Substring(Parentpath.Length - 1, 1) != @"\\") Parentpath = Parentpath + @"\\"; string childPath = Parentpath + DateTime.Now.ToString("yyyyMMdd"); if (!Directory.Exists(childPath)) Directory.CreateDirectory(childPath); pic.Image.Save(childPath + "\\\\" + filename + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); MessageBox.Show("保存成功!"); } } }
实现的效果
保持文件
要把此项目移植到asp.net网站上也是极其简单的,这里就不再演示了。
以上是关于教教我这个功能怎么用asp实现的主要内容,如果未能解决你的问题,请参考以下文章
哪位会用report machine做报表?教教我怎么用好吧?或者教程也行
怎么用asp 做界面 连接 SQL server 实现 增 删 改