A. 上传图片代码修改
<%
Response.Buffer = True
Server.ScriptTimeOut=9999999
On Error Resume Next
%>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<meta content="all" name="robots" />
<meta name="author" content="木目,Woodeye" />
<meta name="description" content="木目ASP文件上传工具" />
<meta name="keywords" content="木目,ASP,Upload,文件上传" />
<style type="text/css">
<!--
body,input {font-size:12px;}
-->
</style>
<title>vip图片上传小于100k</title>
</head>
<body id="body">
<%
ExtName = "jpg,gif,png" '允许扩展名
SavePath = "Upload_img" '保存路径
If Right(SavePath,1)<>"/" Then SavePath=SavePath&"/" '在目录后加(/)
CheckAndCreateFolder(SavePath)
UpLoadAll_a = Request.TotalBytes '取得客户端全部内容
If(UpLoadAll_a>0) Then
If(UpLoadAll_a<=1024*100) Then'=======================此处限制图片大小小于100KB=========================
Set UploadStream_c = Server.CreateObject("ADODB.Stream")
UploadStream_c.Type = 1
UploadStream_c.Open
UploadStream_c.Write Request.BinaryRead(UpLoadAll_a)
UploadStream_c.Position = 0
FormDataAll_d = UploadStream_c.Read
CrLf_e = chrB(13)&chrB(10)
FormStart_f = InStrB(FormDataAll_d,CrLf_e)
FormEnd_g = InStrB(FormStart_f+1,FormDataAll_d,CrLf_e)
Set FormStream_h = Server.Createobject("ADODB.Stream")
FormStream_h.Type = 1
FormStream_h.Open
UploadStream_c.Position = FormStart_f + 1
UploadStream_c.CopyTo FormStream_h,FormEnd_g-FormStart_f-3
FormStream_h.Position = 0
FormStream_h.Type = 2
FormStream_h.CharSet = "GB2312"
FormStreamText_i = FormStream_h.Readtext
FormStream_h.Close
FileName_j = Mid(FormStreamText_i,InstrRev(FormStreamText_i,"\")+1,FormEnd_g)
If(CheckFileExt(FileName_j,ExtName)) Then
SaveFile = Server.MapPath(SavePath & FileName_j)
If Err Then
Response.Write "文件上传: <span style=""color:red;"">文件上传出错!</span> <a href=""" & Request.ServerVariables("URL") &""">重新上传文件</a><br />"
Err.Clear
Else
SaveFile = CheckFileExists(SaveFile)
k=Instrb(FormDataAll_d,CrLf_e&CrLf_e)+4
l=Instrb(k+1,FormDataAll_d,leftB(FormDataAll_d,FormStart_f-1))-k-2
FormStream_h.Type=1
FormStream_h.Open
UploadStream_c.Position=k-1
UploadStream_c.CopyTo FormStream_h,l
FormStream_h.SaveToFile SaveFile,2
SaveFileName = Mid(SaveFile,InstrRev(SaveFile,"\")+1)
Response.write "文件上传: <span style=""color:red;"">" & SaveFileName & " </span>"<html><head><meta http-equiv='Refresh' content='3 url=""javascript:window.close();""'></head><body><center><br><br>文件上传成功<br>本窗口三秒后自动关闭</center></body></html>"<a href=""" & Request.ServerVariables("URL") &"""></a><br />"
End If
Else
Response.write "文件上传: <span style=""color:red;"">文件格式不正确!</span> <a href=""" & Request.ServerVariables("URL") &""">重新上传文件</a><br />"
End If
Else
'=====================此处为提示文件大小超过了=========================
Response.write "上传文件过大,小于100kb! <a href='javascript:history.back()'>返回</a>"
End If
Else
%>
<script language="Javascript">
<!--
function ValidInput()
{
if(document.upform.upfile.value=="")
{
alert("请选择上传文件!")
document.upform.upfile.focus()
return false
}
return true
}
// -->
</script>
<form action='<%= Request.ServerVariables("URL") %>' method='post' name="upform" onsubmit="return ValidInput()" enctype="multipart/form-data">
文件上传:
<input type='file' name='upfile' size="40" />
<input type='submit' value="上传">
</form>
<%
End if
Set FormStream_h = Nothing
UploadStream.Close
Set UploadStream = Nothing
%>
</body>
</html>
<%
'判断文件类型是否合格
Function CheckFileExt(FileName,ExtName) '文件名,允许上传文件类型
FileType = ExtName
FileType = Split(FileType,",")
For i = 0 To Ubound(FileType)
If LCase(Right(FileName,3)) = LCase(FileType(i)) then
CheckFileExt = True
Exit Function
Else
CheckFileExt = False
End if
Next
End Function
'检查上传文件夹是否存在,不存在则创建文件夹
Function CheckAndCreateFolder(FolderName)
fldr = Server.Mappath(FolderName)
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fldr) Then
fso.CreateFolder(fldr)
End If
Set fso = Nothing
End Function
'检查文件是否存在,重命名存在文件
Function CheckFileExists(FileName)
Set fso=Server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(SaveFile) Then
i=1
msg=True
Do While msg
CheckFileExists = Replace(SaveFile,Right(SaveFile,4),"_" & i & Right(SaveFile,4))
If not fso.FileExists(CheckFileExists) Then
msg=False
End If
i=i+1
Loop
Else
CheckFileExists = FileName
End If
Set fso=Nothing
End Function
%>
B. 图片怎么编写HTML代码上传到网上
我可能思想笨,没完全理解你的意思,
你是要在网页中插入图片<img>
在一个是用图片组建上传。
在一个把图片处理为二进制代码,存进数据库,然后通过程序把二进制翻译过来,(建议不要这样,)两张图片填满你的数据库,还有翻译来翻译去,效率很差。
C. asp 上传图片 代码
我嘴笨 代码上!
protected void UpLoad(object sender, EventArgs e)
{
foreach (UploadedFile file in RadUploadContext.Current.UploadedFiles)
{
string Path = Server.MapPath(@"../../Uploads");
//如果路径不存在,则创建
if (System.IO.Directory.Exists(Path) == false)
{
System.IO.Directory.CreateDirectory(Path);
}
//file.GetName()取得文件名
string filename = file.GetName().ToString();
//取得文件名(包括路径)里最后一个"."的索引
int index = filename.LastIndexOf(".");
//取得文件扩展名
string extendName = filename.Substring(index);
//取得原文件名不包含后缀名
string fileNameFirst = filename.Substring(0, index);
//用当前时间为文件重名名,确保文件名不重复
string datename = DateTime.Now.ToString("yyyyMMddHHmmss");
string newFileName = fileNameFirst + datename + extendName;
//组合路径
Path = Path + "/" + newFileName;
//保存
file.SaveAs(Path, true);
this.dataurl.Visible = true;
this.lab2.Visible = true;
this.FileUpload1.Visible = false;
this.Button3.Visible = false;
this.dataurl.ReadOnly=true;
this.dataurl.Text = newFileName;
//Response.Write("f1:" + fileNameFirst);
//Response.Write("f2:" + Path);
}
}
前台:
<th>上传文件:</th>
<td class="style1">
<asp:TextBox runat="server" ID ="dataurl" Width="50%" Visible="false"></asp:TextBox>
<asp:FileUpload ID="FileUpload1" runat="server" Width="65%"/>
<asp:Button ID="Button3" runat="server" Text="上传" OnClick="UpLoad" Height="25" Width="25%"/>
<asp:Label ID ="lab2" runat="server" Text="上传成功!" ForeColor="Red" Visible="false"></asp:Label>
</td>
D. 上传图片到服务器如何写代码
设计里拖一个FileUpload和以个Button
然后在Button_Click事件里写
string FileName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(@"/")+1);//获取文件名字,前面的盘符路径省略;
FileUpload1.PostedFile.SaveAs(Server.MapPath("要上传的盘符名" + FileName));
E. asp图片上传求代码
留邮箱
F. 图片上传的代码
<%@ language="javascript"%>
<%
var self = Request.serverVariables("SCRIPT_NAME");
if (Request.serverVariables("REQUEST_METHOD")=="POST")
{
var oo = new uploadFile();
oo.path = "myFile"; //存放路径,为空表示当前路径,默认为uploadFile
oo.named = "file"; //命名方式,date表示用日期来命名,file表示用文件名本身,默认为file
oo.ext = "all"; //允许上传的扩展名,all表示都允许,默认为all
oo.over = true; //当存在相同文件名时是否覆盖,默认为false
oo.size = 1*1024*1024; //最大字节数限制,默认为1G
oo.upload();
Response.write('<script type="text/javascript">location.replace("'+self+'")</script>');
}
//ASP无组件上传类
function uploadFile()
{
var bLen = Request.totalBytes;
var bText = Request.binaryRead(bLen);
var oo = Server.createObject("ADODB.Stream");
oo.mode = 3;
this.path = "uploadFile";
this.named = "file";
this.ext = "all";
this.over = false;
this.size = 1*1024*1024*1024; //1GB
//文件上传
this.upload = function ()
{
var o = this.getInfo();
if (o.size>this.size)
{
alert("文件过大,不能上传!");
return;
}
var f = this.getFileName();
var ext = f.replace(/^.+\./,"");
if (this.ext!="all"&&!new RegExp(this.ext.replace(/,/g,"|"),"ig").test(ext))
{
alert("目前暂不支持扩展名为 "+ext+" 的文件上传!");
return;
}
if (this.named=="date")
{
f = new Date().toLocaleString().replace(/\D/g,"") + "." + ext;
}
oo.open();
oo.type = 1;
oo.write(o.bin);
this.path = this.path.replace(/[^\/\\]$/,"$&/");
var fso = Server.createObject("Scripting.FileSystemObject");
if(this.path!=""&&!fso.folderExists(Server.mapPath(this.path)))
{
fso.createFolder(Server.mapPath(this.path));
}
try
{
oo.saveToFile(Server.mapPath(this.path+f),this.over?2:1);
alert("上传成功!");
}
catch(e)
{
alert("对不起,此文件已存在!");
}
oo.close();
delete(oo);
}
//获取二进制和文件字节数
this.getInfo = function ()
{
oo.open();
oo.type=1;
oo.write(bText);
oo.position = 0;
oo.type=2;
oo.charset="unicode";
var gbCode=escape(oo.readText()).replace(/%u(..)(..)/g,"%$2%$1");
var sPos=gbCode.indexOf("%0D%0A%0D%0A")+12;
var sLength=bLen-(gbCode.substring(0,gbCode.indexOf("%0D%0A")).length/3)-sPos/3-6;
oo.close();
oo.open();
oo.type = 1;
oo.write(bText);
oo.position=sPos/3;
var bFile=oo.read(sLength);
oo.close();
return { bin:bFile, size:sLength };
}
//获取文件名
this.getFileName = function ()
{
oo.open();
oo.type = 2;
oo.writeText(bText);
oo.position = 0;
oo.charset = "gb2312";
var fileName = oo.readText().match(/filename=\"(.+?)\"/i)[1].split("\\").slice(-1)[0];
oo.close();
return fileName;
}
function alert(msg)
{
Response.write('<script type="text/javascript">alert("'+msg+'");</script>');
}
}
%>
<html>
<head>
<title>ASP无组件上传类</title>
<meta http-equiv="content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form action="<%=self%>" method="post" enctype="multipart/form-data" onSubmit="return (this.upFile.value!='');">
<input type="file" name="upFile"/>
<input type="submit" value="上传文件"/>
</form>
</body>
</html>
G. 求JAVA上传图片代码
package com;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import com.jspsmart.upload.*;
public class uploadfiles extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
//使用了一个第三方的组件,存放在web-inf/lib下
response.setContentType("text/html;charset=GB2312");
//由于SmartUpload的初始化方法需要pageContext,所以我们在servlet中得到他
//为了得到pageConext要首先得到JspFactory的实例
//通过JspFactory的实例的getPageContext方法得到pageConext的实例
JspFactory jf = null;
//得到JspFactory的实例
jf=JspFactory.getDefaultFactory();
/*
getPageContext(Servlet servlet,
ServletRequest request,
ServletResponse response,
java.lang.String errorPageURL,
boolean needsSession,
int buffer,
boolean autoflush)
*/
PageContext pageContext=jf.getPageContext(this,request,response,null,true,8192,true);
try
{
//实例化SmartUpload
SmartUpload mySmartUpload=new SmartUpload();
//初始化SmartUpload的实例,需要PageContext的实例
mySmartUpload.initialize(pageContext);
//设定最大上传的字节数,其实可以不进行设定,表示上传的文件没有大小限制
//mySmartUpload.setTotalMaxFileSize(10000000);
mySmartUpload.upload();
//下面是单文件上传
//上传的文件以com.jspsmart.upload.File 代表,如果文件名称重复,则进行覆盖
com.jspsmart.upload.File file=mySmartUpload.getFiles().getFile(0);
String upLoadFileName=file.getFileName();
//调用com.jspsmart.upload.File实例的saveas的方法保存文件,此时的文件名即是
//保存到服务器上的文件名
file.saveAs("/upload/"+upLoadFileName);
Request req =
Text t = .....;
t.setUpload(upLoadFileName);
t.set.....(req);
}
catch(SmartUploadException e)
{
System.out.println(e.getMessage());
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException
{
doGet(request,response);
}
}
H. android 怎么写上传图片代码
请问图片是放在android手机的哪个地方,要在android手机怎么显示返回呢,主类中有个按钮来添加图片,还有一个按钮是用来上传图片,然后写个监听,
I. 怎么把图片上传到网站上,然后可以提取图片代码
你把这张图片放到QQ的相册里,然后右键它的属性,就会有一个地址,用这个地址就可以了