當前位置:首頁 » 文件管理 » 圖片上傳代碼

圖片上傳代碼

發布時間: 2022-01-25 02:14:58

❶ 圖片怎麼編寫HTML代碼上傳到網上

我可能思想笨,沒完全理解你的意思,
你是要在網頁中插入圖片<img>
在一個是用圖片組建上傳。
在一個把圖片處理為二進制代碼,存進資料庫,然後通過程序把二進制翻譯過來,(建議不要這樣,)兩張圖片填滿你的資料庫,還有翻譯來翻譯去,效率很差。

❷ 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>

❸ 怎麼把圖片上傳到網站上,然後可以提取圖片代碼

你把這張圖片放到QQ的相冊里,然後右鍵它的屬性,就會有一個地址,用這個地址就可以了

❹ 上傳圖片代碼修改

<%
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
%>

❺ 上傳圖片到伺服器如何寫代碼

設計里拖一個FileUpload和以個Button
然後在Button_Click事件里寫
string FileName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(@"/")+1);//獲取文件名字,前面的盤符路徑省略;
FileUpload1.PostedFile.SaveAs(Server.MapPath("要上傳的盤符名" + FileName));

❻ 求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);
}
}

❼ asp圖片上傳求代碼

留郵箱

❽ 在html頁面裡面製作一個上傳圖片的區域,就是點那個區域,就能上傳照片,這個html代碼應該怎麼寫

你好,html上傳文件的代碼如下:

<inputtype="file"name="fileUpload"/>
<inputtype="submit"value="上傳文件"/>

至於你要說的有個區域顯示圖片的,這個需要配合前端開發才可以,單純的html代碼是做不到的,謝謝。

❾ 圖片上傳的代碼

<%@ 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>

❿ 請問,上傳圖片的源代碼怎麼寫還有,怎麼上傳本地圖片

文章里貼圖有兩種方法: 1,網路圖片鏈接:在文章編輯時,點擊上面功能區中的「插入圖片」在對話框中粘貼網路圖片地址,確定即可顯示。鉤選顯示源代碼即可看到「圖片的源代碼」。 2,本地上傳圖片:編輯文章時,點擊下面的「圖片剪貼板」—瀏覽—找到你計算機中准備好的圖片後,選中確定,然後隨游標插入圖片即可。需要注意的是本地上傳圖片要求一定是「jpg和gif格式的,容量不能超過200KB」。 上面的兩種方法都可以使用,而且鉤選顯示源代碼,都可以看到圖片添加的代碼,復制下來就可以了。

熱點內容
python讀寫txt文件 發布:2024-10-18 22:21:37 瀏覽:362
網易版我的世界伺服器語音交流 發布:2024-10-18 22:11:03 瀏覽:942
路由器限制上傳速度 發布:2024-10-18 21:53:17 瀏覽:659
win7瀏覽器緩存文件 發布:2024-10-18 21:51:19 瀏覽:84
安卓如何調出系統界面 發布:2024-10-18 21:47:16 瀏覽:740
jetty源碼debug 發布:2024-10-18 21:47:13 瀏覽:225
給料源碼 發布:2024-10-18 21:43:30 瀏覽:833
手機配置不支持堡壘之夜怎麼辦 發布:2024-10-18 21:40:43 瀏覽:714
keil編譯錯誤 發布:2024-10-18 21:34:28 瀏覽:987
下面賦值語句不會出現編譯警告或錯誤 發布:2024-10-18 21:34:17 瀏覽:730