⑴ 图片批量上传代码
用这个插件吧,jspsmartupload
upload.html页面
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p></p>
<p align="center">上传文件选择</p>
<FORM METHOD="POST" ACTION="jsp/do_upload.jsp"
ENCTYPE="multipart/form-data">
<input type="hidden" name="TEST" value="good">
<table width="75%" border="1" align="center">
<tr>
<td><div align="center">1、
<input type="FILE" name="FILE1" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">2、
<input type="FILE" name="FILE2" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">3、
<input type="FILE" name="FILE3" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">4、
<input type="FILE" name="FILE4" size="30">
</div></td>
</tr>
<tr>
<td><div align="center">
<input type="submit" name="Submit" value="上传它!">
</div></td>
</tr>
</table>
</FORM>
</body>
</html>
do_upload.jsp页面
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.util.*,com.jspsmart.upload.*" errorPage="" %>
<html>
<head>
<title>文件上传处理页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
// 上传初始化
su.initialize(pageContext);
// 设定上传限制
// 1.限制每个上传文件的最大长度。
// su.setMaxFileSize(10000);
// 2.限制总上传数据的长度。
// su.setTotalMaxFileSize(20000);
// 3.设定允许上传的文件(通过扩展名限制),仅允许doc,txt文件。
// su.setAllowedFilesList("doc,txt");
// 4.设定禁止上传的文件(通过扩展名限制),禁止上传带有exe,bat,
jsp,htm,html扩展名的文件和没有扩展名的文件。
// su.setDeniedFilesList("exe,bat,jsp,htm,html,,");
// 上传文件
su.upload();
// 将上传文件全部保存到指定目录
int count = su.save("/upload");
out.PRintln(count+"个文件上传成功!<br>");
// 利用Request对象获取参数之值
out.println("TEST="+su.getRequest().getParameter("TEST")
+"<BR><BR>");
// 逐一提取上传文件信息,同时可保存文件。
for (int i=0;i<su.getFiles().getCount();i++)
{
com.jspsmart.upload.File file = su.getFiles().getFile(i);
// 若文件不存在则继续
if (file.isMissing()) continue;
// 显示当前文件信息
out.println("<TABLE BORDER=1>");
out.println("<TR><TD>表单项名(FieldName)</TD><TD>"
+ file.getFieldName() + "</TD></TR>");
out.println("<TR><TD>文件长度(Size)</TD><TD>" +
file.getSize() + "</TD></TR>");
out.println("<TR><TD>文件名(FileName)</TD><TD>"
+ file.getFileName() + "</TD></TR>");
out.println("<TR><TD>文件扩展名(FileExt)</TD><TD>"
+ file.getFileExt() + "</TD></TR>");
out.println("<TR><TD>文件全名(FilePathName)</TD><TD>"
+ file.getFilePathName() + "</TD></TR>");
out.println("</TABLE><BR>");
// 将文件另存
// file.saveAs("/upload/" + myFile.getFileName());
// 另存到以WEB应用程序的根目录为文件根目录的目录下
// file.saveAs("/upload/" + myFile.getFileName(),
su.SAVE_VIRTUAL);
// 另存到操作系统的根目录为文件根目录的目录下
// file.saveAs("c:\\temp\\" + myFile.getFileName(),
su.SAVE_PHYSICAL);
}
%>
</body>
</html>
参考资料来源:http://www.knowsky.com/3136.html
呵呵 正好前端时间我 也用到了
⑵ JSP上传图片怎么实现 求源代码
⑶ 图片上传的代码
<%@ 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>
⑷ 上传图片代码修改
<%
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
%>
⑸ 急求!!!!thinkphp+uploadify 实现图片上传预览 源码
js代码:
$('#picture').uploadify({
swf:PUBLIC+'/Uploadify/uploadify.swf', //引入Uploadify核心Flash文件
uploader:uploadUrl, //PHP处理脚本地址
width:120, //上传按钮宽度
height:30, //上传按钮高度
buttonImage:PUBLIC+'/Uploadify/browse-btn.png', //上传按钮背景图地址
fileTypeDesc:'ImageFile', //选择文件提示文字
fileTypeExts:'*.jpeg;*.jpg;*.png;*.gif', //允许选择的文件类型
formData:{'session_id':sid},
//上传成功后的回调函数
onUploadSuccess:function(file,data,response){
if(data){
$('input[name=max]').val(data);
$('#upload_img').fadeOut().next().fadeIn().find('img').attr('src',ROOT+'/Uploads/'+data);
}else{
alert(data.msg);
}
}
});
php代码:
public function uploadPic(){
$upload = new ThinkUpload(); // 实例化上传类
$upload->maxSize = C('UPLOAD_MAX_SIZE') ;// 设置附件上传大小
$upload->exts = C('UPLOAD_EXTS');// 设置附件上传类型
$upload->rootPath = C('UPLOAD_PATH'); // 设置附件上传根目录
$upload->savePath = 'pic/'; // 设置附件上传目录
$upload->subName = date('Y-m');//子目录创建方式
$upload->saveName = array('uniqid',''); //上传文件的保存规则
$upload->replace = true;//同名文件覆盖
// 开启子目录保存 并以日期(格式为Ymd)为子目录
$upload->autoSub = true;
$upload->subName = array('date','Y-m');
$info=$upload->upload();
// 上传文件
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());//获取失败信息
}else{
$images=$info['Filedata']['savepath'].$info['Filedata']['savename'];
//返回文件地址和名给JS作回调用
echo $images;
}
}
⑹ 我有个图片要上传替换到网站源代码
你这段代码中压根就不包含图片,你可以把整个文件发出来,帮你看下怎么修改!
⑺ 求网页制作图片上传代码
upfile.asp 上传的图片存到images/upfile文件夹下。
<!--#include FILE="upfile"-->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%
if Request("menu")="up" then
On Error Resume Next
Set upl = Server.CreateObject("SoftArtisans.FileUp")
If -2147221005 = Err Then
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
set FileUP=new Upload_file
FileUP.GetDate(-1)
formPath="images/upfile/"
set file=FileUP.file("file")
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&"."&file.FileExt
select case LCase(file.FileExt)
case "gif"
img="[img]"&cluburl&"/"&filename&"[/img]"
case "jpg"
img="[img]"&cluburl&"/"&filename&"[/img]"
case "swf"
img="[flash]"&cluburl&"/"&filename&"[/flash]"
case else
error2("Sorry ,this local server only supports GIF , JPG and SWF format of files\n does not support "&file.FileExt&" format of files")
end select
file.SaveToFile Server.mappath(filename)
set FileUP=nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
else
filename=""&year(date)&""&month(date)&""&day(date)&""&hour(time)&""&minute(time)&""&second(time)&""
select case ""&upl.ContentType&""
case "application/octet-stream"
error2("Unknown file format!")
case "image/gif"
types="gif"
case "image/pjpeg"
types="jpg"
case "application/x-shockwave-flash"
types="swf"
end select
filename="images/upfile/"&filename&"."&types&""
if types="gif" or types="jpg" then
img="[img]"&cluburl&"/"&filename&"[/img]"
elseif types="swf" then
img="[flash]"&cluburl&"/"&filename&"[/flash]"
else
error2("Sorry ,this local server only supports GIF , JPG and SWF format of files\n does not support "&upl.ContentType&"format of files")
end if
upl.SaveAs Server.mappath(""&filename&"")
set upl=nothing
End If
response.write "<SCRIPT>parent.myform.pic.value='admin/"&filename&"'</SCRIPT>"
responseend
else
%>
<body topmargin=0>
<table cellpadding=0 cellspacing=0 width=100% height="20">
<form enctype=multipart/form-data method=post action=upfile.asp?menu=up>
<tr><td>
<input type=file style=FONT-SIZE:9pt name=file size="2"> <input style=FONT-SIZE:9pt type="submit" value="Upload" name=Submit>
</td></tr></form></table>
<%
end if
%>
⑻ 把图片上传以后‘链接怎么变为代码
把链接变成代码?没明白你的意思是变成哪类代码。
能详细些吗,或者举个例子。
⑼ 如何编写上传和下载图片的前台代码和后台代码
";}else{string filepath = FileUpload1.PostedFile.FileName; string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1); string serverpath = Server.MapPath("images/") + filename; FileUpload1.PostedFile.SaveAs(serverpath); this.lb_info.Text = "上传成功!";}}catch (Exception ex){this.lb_info.Text = "上传发生错误!原因是:" + ex.ToString();}}}前台代码: 单文件上传