導航:首頁 > 源碼編譯 > 圖片上傳源碼

圖片上傳源碼

發布時間:2022-01-21 11:46:20

⑴ 圖片批量上傳代碼

用這個插件吧,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();}}}前台代碼: 單文件上傳

閱讀全文

與圖片上傳源碼相關的資料

熱點內容
三星qx2是什麼安卓系統 瀏覽:203
保鮮膜解壓球教學視頻 瀏覽:601
多媒體演算法工程師camera 瀏覽:987
電腦下載的歌可以拉到文件夾嗎 瀏覽:722
千鋒3g學院android 瀏覽:445
linux中的yum命令 瀏覽:239
壓縮面膜有幾種 瀏覽:575
怎麼更改安卓程序級別 瀏覽:393
安卓系統運行慢怎麼辦呢 瀏覽:808
外地人在買車本地可以解壓嘛 瀏覽:907
相冊軟體加密怎麼取消 瀏覽:251
麥克風app怎麼打開 瀏覽:22
java泛型t和 瀏覽:356
計算機英文pdf 瀏覽:587
單片機控制的直流調速系統 瀏覽:130
抖音上解壓視頻書單號怎麼做 瀏覽:165
軟體加密之後忘了密碼怎麼辦 瀏覽:944
文件夾怎麼彈出來的 瀏覽:209
51單片機引腳圖電路 瀏覽:214
麥當勞員工怎麼登錄app 瀏覽:530