當前位置:ag真人国际官网-ag旗舰厅官方网站 » 文件管理 » 上傳圖片到伺服器

上傳圖片到伺服器-ag真人国际官网

發布時間: 2022-01-07 23:34:56

① 如何上傳圖片到圖片伺服器

使用一些已有的組件幫助我們實現這種上傳功能。 常用的上傳組件: apache 的 commons fileupload javazoom的uploadbean jspsmartupload 以下,以fileupload為例講解 1、在jsp端

要注意enctype="multipart/form-data" 然後只需要放置一個file控制項,並執行submit操作即可 2、web端 核心代碼如下: public void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { request.setcharacterencoding("utf-8"); diskfileitemfactory factory = new diskfileitemfactory(); servletfileupload upload = new servletfileupload(factory); try { list items = upload.parserequest(request); iterator itr = items.iterator(); while (itr.hasnext()) { fileitem item = (fileitem) itr.next(); if (item.isformfield()) { system.out.println("表單參數名:" item.getfieldname() ",表單參數值:" item.getstring("utf-8")); } else { if (item.getname() != null && !item.getname().equals("")) { system.out.println("上傳文件的大小:" item.getsize()); system.out.println("上傳文件的類型:" item.getcontenttype()); system.out.println("上傳文件的名稱:" item.getname()); file tempfile = new file(item.getname()); file file = new file(sc.getrealpath("/") savepath, tempfile.getname()); item.write(file); request.setattribute("upload.message", "上傳文件成功!"); }else{ request.setattribute("upload.message", "沒有選擇上傳文件!"); } } } }catch(fileuploadexception e){ e.printstacktrace(); } catch (exception e) { e.printstacktrace(); request.setattribute("upload.message", "上傳文件失敗!"); } request.getrequestdispatcher("/uploadresult.jsp").forward(request, response); }

② file怎樣上傳圖片到伺服器

首先把xml文件的內容存到資料庫裡面的某個表
sqlcommand com=new sqlcommand("select * from 表");
com.commtype=commtype.text;
然後把sqlcommand傳遞給webservice
因為對方的webservice介面是需要使用post方式調用的,然後告訴我post參數是command,但是我不是很理解這個command指的是什麼。其他也沒有說明,就只有一個介面接入地址和數據格式。

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

設計里拖一個fileupload和以個button
然後在button_click事件里寫
string filename = fileupload1.postedfile.filename.substring(fileupload1.postedfile.filename.lastindexof(@"/") 1);//獲取文件名字,前面的盤符路徑省略;
fileupload1.postedfile.saveas(server.mappath("要上傳的盤符名" filename));

④ html5如何上傳圖片到伺服器

直接用ftp工具,將你.html或者.htm結尾的文件放到伺服器的運行目錄
然後通過你的網站/html名字.html。

⑤ 本地電腦的圖片怎麼上傳到伺服器

如果你是通過後台,打開伺服器,然後把文件拖進去~~~ 如果你是指上傳到網站 網盤等地方。點擊上傳,然後選擇圖片,然後確定。如果沒有上傳這個選項,則上傳不了。

⑥ java 中如何向伺服器上傳圖片

我們使用一些已有的組件幫助我們實現這種上傳功能。
常用的上傳組件:
apache 的 commons fileupload
javazoom的uploadbean
jspsmartupload
以下,以fileupload為例講解
1、在jsp端

要注意enctype="multipart/form-data"
然後只需要放置一個file控制項,並執行submit操作即可


2、web端
核心代碼如下:
public void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
request.setcharacterencoding("utf-8");
diskfileitemfactory factory = new diskfileitemfactory();
servletfileupload upload = new servletfileupload(factory);
try {
list items = upload.parserequest(request);
iterator itr = items.iterator();
while (itr.hasnext()) {
fileitem item = (fileitem) itr.next();
if (item.isformfield()) {
system.out.println("表單參數名:" item.getfieldname() ",表單參數值:" item.getstring("utf-8"));
} else {
if (item.getname() != null && !item.getname().equals("")) {
system.out.println("上傳文件的大小:" item.getsize());
system.out.println("上傳文件的類型:" item.getcontenttype());
system.out.println("上傳文件的名稱:" item.getname());
file tempfile = new file(item.getname());
file file = new file(sc.getrealpath("/") savepath, tempfile.getname());
item.write(file);
request.setattribute("upload.message", "上傳文件成功!");
}else{
request.setattribute("upload.message", "沒有選擇上傳文件!");
}
}
}
}catch(fileuploadexception e){
e.printstacktrace();
} catch (exception e) {
e.printstacktrace();
request.setattribute("upload.message", "上傳文件失敗!");
}
request.getrequestdispatcher("/uploadresult.jsp").forward(request, response);
}

⑦ 怎樣將圖片上傳到伺服器

工具/原料 flashfxp vpn 文件夾步驟/方法 首先建立一個文件夾,把當天需要上傳的圖片存放到同一個文件夾,這樣不會和以前的圖片混淆一起難以辨認。然後就是連接到vpn,輸入vpn用戶名以及密碼,連接成功。打開flashfxp,這個工具是上傳圖片的直接工具,首先連接到伺服器,點擊圓圈箭頭處的連接圖標,輸入連接類型、用戶名、密碼,連接成功。在flashfxp工具的左欄的圓圈處打開開始創建的新文件夾,在flashfxp工具的左欄的圓圈處打開一個新文件夾,這個很重要,最好是每天上傳圖片到伺服器中建立一個新的文件夾。將要上傳的圖片直接復制、粘貼到左欄框內,點擊滑鼠右鍵彈出的傳輸指令,然後上傳到伺服器成功。圖片上次伺服器已成功,然後就可以用代碼的格式編輯到文章中。注意事項 最好是每天上傳圖片到伺服器中建立一個新的文件夾。文件夾不要隨便更改其初始位置。圖片修改成較容易記的名稱,因為在插入圖片時要用源代碼的形式輸入圖片名稱。 更多精彩電腦信息,請登錄:中國高速網-it頻道。

⑧ 如何實現上傳文件到伺服器

common-fileupload是jakarta項目組開發的一個功能很強大的上傳文件組件
下面先介紹上傳文件到伺服器(多文件上傳):
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import org.apache.commons.fileupload.*;

public class upload extends httpservlet {
private static final string content_type = "text/html; charset=gb2312";
//process the http post request
public void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
response.setcontenttype(content_type);
printwriter out=response.getwriter();
try {
diskfileupload fu = new diskfileupload();
// 設置允許用戶上傳文件大小,單位:位元組,這里設為2m
fu.setsizemax(2*1024*1024);
// 設置最多隻允許在內存中存儲的數據,單位:位元組
fu.setsizethreshold(4096);
// 設置一旦文件大小超過getsizethreshold()的值時數據存放在硬碟的目錄
fu.setrepositorypath("c://windows//temp");
//開始讀取上傳信息
list fileitems = fu.parserequest(request);
// 依次處理每個上傳的文件
iterator iter = fileitems.iterator();
//正則匹配,過濾路徑取文件名
string regexp=". ////(. )$";
//過濾掉的文件類型
string[] errortype={".exe",".com",".cgi",".asp"};
pattern p = pattern.compile(regexp);
while (iter.hasnext()) {
fileitem item = (fileitem)iter.next();
//忽略其他不是文件域的所有表單信息
if (!item.isformfield()) {
string name = item.getname();
long size = item.getsize();
if((name==null||name.equals("")) && size==0)
continue;
matcher m = p.matcher(name);
boolean result = m.find();
if (result){
for (int temp=0;temp if (m.group(1).endswith(errortype[temp])){
throw new ioexception(name ": wrong type");
}
}
try{
//保存上傳的文件到指定的目錄
//在下文中上傳文件至資料庫時,將對這里改寫
item.write(new file("d://" m.group(1)));
out.print(name " " size "");
}
catch(exception e){
out.println(e);
}
}
else
{
throw new ioexception("fail to upload");
}
}
}
}
catch (ioexception e){
out.println(e);
}
catch (fileuploadexception e){
out.println(e);
}

}
}
現在介紹上傳文件到伺服器,下面只寫出相關代碼:
以sql2000為例,表結構如下:
欄位名:name filecode
類型: varchar image
資料庫插入代碼為:preparedstatement pstmt=conn.preparestatement("insert into test values(?,?)");
代碼如下:
。。。。。。
try{
這段代碼如果不去掉,將一同寫入到伺服器中
//item.write(new file("d://" m.group(1)));

int byteread=0;
//讀取輸入流,也就是上傳的文件內容
inputstream instream=item.getinputstream();
pstmt.setstring(1,m.group(1));
pstmt.setbinarystream(2,instream,(int)size);
pstmt.executeupdate();
instream.close();
out.println(name " " size " ");
}
。。。。。。
這樣就實現了上傳文件至資料庫

⑨ 怎樣上傳文件到linux伺服器

常見有使用:scp命令、xshell軟體里的xftp程序、u盤掛載、伺服器自帶的lrzsz程序。

一、scp使用說明:

1、把本機的文件傳給目的伺服器:


[email protected]:/super

備註:把本機get66.pcap拷貝到147這台伺服器的super目錄下,需要提供147的密碼

2、在本機上執行scp,把遠端的伺服器文件拷貝到本機上:


[email protected]:/super/dns.pcap/

備註:在本機上執行scp,把遠端伺服器的dns.pcap文件拷貝到本機的根目錄下

3、拷貝目錄下的所有文件:


scp-r/super/[email protected]:/

備註:把/super/目錄下的所有文件,拷貝到145伺服器根目錄下

二、xshell軟體里的xftp程序:

xshell這個軟體很好,強烈推薦哦!!!

裡面有個xftp小插件,可以支持文件在筆記本和伺服器互傳,這個小插件需要單獨在網上下載,直接網路搜xftp,很方便。

1、點擊xshell軟體上的xftp圖標(前提xftp已經下載好)

⑩ java 上傳圖片到伺服器

你需需要明白,java數據通信,http協議,tcp協議,udp協議,你上面用的post、get就是http協議的內容

熱點內容
sqlserver如何切換主備伺服器 發布:2024-07-17 16:23:02 瀏覽:298
mc18伺服器ip 發布:2024-07-17 16:23:02 瀏覽:378
仙境傳說手游腳本 發布:2024-07-17 16:09:24 瀏覽:690
matlab命令窗口和新建腳本 發布:2024-07-17 15:51:26 瀏覽:374
建ftp文件夾 發布:2024-07-17 15:51:26 瀏覽:954
魔獸撿物腳本 發布:2024-07-17 15:27:56 瀏覽:129
開發ip伺服器 發布:2024-07-17 15:24:42 瀏覽:387
安卓系統視頻製作哪個好用 發布:2024-07-17 15:10:47 瀏覽:210
androidapk結構 發布:2024-07-17 15:10:43 瀏覽:945
c語言指針的例子 發布:2024-07-17 15:08:01 瀏覽:768
网站地图