當前位置:首頁 » 文件管理 » 上傳文件表單

上傳文件表單

發布時間: 2022-02-18 07:04:13

1. 怎麼在form里分別上傳多個文件,如圖

可以用iframe上傳,orm表單的method、 enctype屬性必須和下面代碼一樣。然後將target的值設為iframe的name,這樣就可以實現無刷新上傳文件。
<form action="uploadfile.php" enctype="multipart/form-data" method="post" target="iframeUpload">
<iframe name="iframeUpload" src="" width="350" height="35" frameborder=0 SCROLLING="no" style="display:NONE"></iframe>
<input id="test_file" name="test_file" type="file">
<input value="上傳文件" type="submit">
</form>

2. 支持文件上傳的html表單

/可以理解為關閉符號,關閉的是input name ="myfile"type="file"
input是可以不用關閉的
tmp是 temporal 暫時的
dir是 directory 目錄
都是變數名,不必糾結

3. 怎樣把上傳文件和其他數據,在同一個表單提交

如果還想獲取除了上傳文件以外的其他提交信息,只要在上傳類後面讀取就可以了: 以下為檢驗頁面代碼: '--上傳類函數開始-- dim upload set upload=New UpLoadClass upload.MaxSize = 1048000 upload.FileType = "jpg/g..

4. 為什麼上傳文件的表單需要設置enctype="multipart/form-data

表單中enctype="multipart/form-data"的意思,是設置表單的MIME編碼。默認情況,這個編碼格式是application/x-www-form-urlencoded,不能用於文件上傳;只有使用了multipart/form-data,才能完整的傳遞文件數據,進行下面的操作.

5. form表單怎麼能直接提交ftp伺服器上,把文件上傳到ftp伺服器上!

沒辦法直接傳的!
你只能用表單先傳到web伺服器上,
然後再從web伺服器上傳到FTP上!(可以自己寫一個服務程序)

6. 如何使用multipart/form-data格式上傳文件

在網路編程過程中需要向伺服器上傳文件。Multipart/form-data是上傳文件的一種方式。

Multipart/form-data其實就是瀏覽器用表單上傳文件的方式。最常見的情境是:在寫郵件時,向郵件後添加附件,附件通常使用表單添加,也就是用multipart/form-data格式上傳到伺服器。


表單形式上傳附件

具體的步驟是怎樣的呢?

首先,客戶端和伺服器建立連接(TCP協議)。

第二,客戶端可以向伺服器端發送數據。因為上傳文件實質上也是向伺服器端發送請求。

第三,客戶端按照符合「multipart/form-data」的格式向伺服器端發送數據。

既然Multipart/form-data格式就是瀏覽器用表單提交數據的格式,我們就來看看文件經過瀏覽器編碼後是什麼樣子。

這行指出這個請求是「multipart/form-data」格式的,且「boundary」是 「---------------------------7db15a14291cce」這個字元串。

不難想像,「boundary」是用來隔開表單中不同部分數據的。例子中的表單就有 2 部分數據,用「boundary」隔開。「boundary」一般由系統隨機產生,但也可以簡單的用「-------------」來代替。

實際上,每部分數據的開頭都是由"--" + boundary開始,而不是由 boundary 開始。仔細看才能發現下面的開頭這段字元串實際上要比 boundary 多了個 「--」

緊接著 boundary 的是該部分數據的描述。

接下來才是數據。


「GIF」gif格式圖片的文件頭,可見,unknow1.gif確實是gif格式圖片。

在請求的最後,則是 "--" + boundary + "--" 表明表單的結束。

需要注意的是,在html協議中,用 「 」 換行,而不是 「 」。

下面的代碼片斷演示如何構造multipart/form-data格式數據,並上傳圖片到伺服器。

//---------------------------------------

// this is the demo code of using multipart/form-data to upload text and photos.

// -use WinInet APIs.

//

//

// connection handlers.

//

HRESULT hr;

HINTERNET m_hOpen;

HINTERNET m_hConnect;

HINTERNET m_hRequest;

//

// make connection.

//

...

//

// form the content.

//

std::wstring strBoundary = std::wstring(L"------------------");

std::wstring wstrHeader(L"Content-Type: multipart/form-data, boundary=");

wstrHeader += strBoundary;

HttpAddRequestHeaders(m_hRequest, wstrHeader.c_str(), DWORD(wstrHeader.size()), HTTP_ADDREQ_FLAG_ADD);

//

// "std::wstring strPhotoPath" is the name of photo to upload.

//

//

// uploaded photo form-part begin.

//

std::wstring strMultipartFirst(L"--");

strMultipartFirst += strBoundary;

strMultipartFirst += L" Content-Disposition: form-data; name="pic"; filename=";

strMultipartFirst += L""" + strPhotoPath + L""";

strMultipartFirst += L" Content-Type: image/jpeg ";

//

// "std::wstring strTextContent" is the text to uploaded.

//

//

// uploaded text form-part begin.

//

std::wstring strMultipartInter(L" --");

strMultipartInter += strBoundary;

strMultipartInter += L" Content-Disposition: form-data; name="status" ";

std::wstring wstrPostDataUrlEncode(CEncodeTool::Encode_Url(strTextContent));

// add text content to send.

strMultipartInter += wstrPostDataUrlEncode;

std::wstring strMultipartEnd(L" --");

strMultipartEnd += strBoundary;

strMultipartEnd += L"-- ";

//

// open photo file.

//

// ws2s(std::wstring)

// -transform "strPhotopath" from unicode to ansi.

std::ifstream *pstdofsPicInput = new std::ifstream;

pstdofsPicInput->open((ws2s(strPhotoPath)).c_str(), std::ios::binary|std::ios::in);

pstdofsPicInput->seekg(0, std::ios::end);

int nFileSize = pstdofsPicInput->tellg();

if(nPicFileLen == 0)

{

return E_ACCESSDENIED;

}

char *pchPicFileBuf = NULL;

try

{

pchPicFileBuf = new char[nPicFileLen];

}

catch(std::bad_alloc)

{

hr = E_FAIL;

}

if(FAILED(hr))

{

return hr;

}

pstdofsPicInput->seekg(0, std::ios::beg);

pstdofsPicInput->read(pchPicFileBuf, nPicFileLen);

if(pstdofsPicInput->bad())

{

pstdofsPicInput->close();

hr = E_FAIL;

}

delete pstdofsPicInput;

if(FAILED(hr))

{

return hr;

}

// Calculate the length of data to send.

std::string straMultipartFirst = CEncodeTool::ws2s(strMultipartFirst);

std::string straMultipartInter = CEncodeTool::ws2s(strMultipartInter);

std::string straMultipartEnd = CEncodeTool::ws2s(strMultipartEnd);

int cSendBufLen = straMultipartFirst.size() + nPicFileLen + straMultipartInter.size() + straMultipartEnd.size();

// Allocate the buffer to temporary store the data to send.

PCHAR pchSendBuf = new CHAR[cSendBufLen];

memcpy(pchSendBuf, straMultipartFirst.c_str(), straMultipartFirst.size());

memcpy(pchSendBuf + straMultipartFirst.size(), (const char *)pchPicFileBuf, nPicFileLen);

memcpy(pchSendBuf + straMultipartFirst.size() + nPicFileLen, straMultipartInter.c_str(), straMultipartInter.size());

memcpy(pchSendBuf + straMultipartFirst.size() + nPicFileLen + straMultipartInter.size(), straMultipartEnd.c_str(), straMultipartEnd.size());

//

// send the request data.

//

HttpSendRequest(m_hRequest, NULL, 0, (LPVOID)pchSendBuf, cSendBufLen)

7. 請問一下,上傳文件時,一個按鈕實現同一個頁面的兩個form表單先後分別提交你是怎麼樣實現的

這樣不可以,它只能提交一個請求,如果你想要提交兩個form裡面的內容,直接把他們合成一個form ,我想你大概是這個意思提交fm2之後驗證用戶之後在提交fm1上傳文件,建議第一個form的action=submittext.do 用ajax做,第二個form是真正業務邏輯的提交

Ajax開發的例子
<script language="javascript">
var http_request = false;
function send_request(url) {//初始化、指定處理函數、發送請求的函數 http_request = false; //開始初始化XMLHttpRequest對象
if(window.XMLHttpRequest) { //Mozilla 瀏覽器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//設置MiME類別 http_request.overrideMimeType("text/xml");
}
}
else if (window.ActiveXObject) { // IE瀏覽器
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) { try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) { // 異常,創建對象實例失敗
window.alert("不能創建XMLHttpRequest對象實例.");
return false;
}
http_request.onreadystatechange = processRequest; // 確定發送請求的方式和URL以及是否同步執行下段代碼
http_request.open("GET", url, true);
http_request.send(null); } // 處理返回信息的函數
function processRequest() {
if (http_request.readyState == 4) { // 判斷對象狀態

if (http_request.status == 200) { // 信息已經成功返回,開始處理信息
alert(http_request.responseText);
} else { //頁面不正常
alert("您所請求的頁面有異常。");
}
}
}
</script>

8. Java中上傳文件和表單數據提交如何質蕕

//1.form表單
//註:上傳文件的表單,需要將form標簽設置enctype="multipart/form-data"屬性,意思是將Content-Type設置成multipart/form-data
<form action="xxx" method="post" enctype="multipart/form-data">
<input type="text" name="name" id="id1" /> <br />
<input type="password" name="password" /> <br />
<input type="file" name="file" value="選擇文件"/> <input id="submit_form" type="submit" value="提交"/>
</form>
//2.servlet實現文件接收的功能
boolean isMultipart = ServletFileUpload.isMultipartContent(request);//判斷是否是表單文件類型

DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(factory);
List items = sfu.parseRequest(request);//從request得到所有上傳域的列表
for(Iterator iter = items.iterator();iter.hasNext();){
FileItem fileitem =(FileItem) iter.next(); if(!fileitem.isFormField()&&fileitem!=null){
//判讀不是普通表單域即是file
System.out.println("name:"+fileitem.getName());
}
}

3.擴展一下springboot
@RequestMapping("/xxx")
@ResponseBody
public String handleFileUpload(@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
try {
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(new File(
file.getOriginalFilename())));
System.out.println(file.getName());
out.write(file.getBytes());
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
return "上傳失敗," + e.getMessage();
} catch (IOException e) {
e.printStackTrace();
return "上傳失敗," + e.getMessage();
}
return "上傳成功";
} else {
return "上傳失敗,因為文件是空的.";
}
}

9. 怎麼在上傳文件的同時提交表單

可以用「風聲無組件」上傳,如果還想獲取除了上傳文件以外的其他提交信息,只要在上傳類後面讀取就可以了:
以下為檢驗頁面代碼:
<!--#include file="FSUpClass.asp"-->
'--上傳類函數開始--
dim upload
set upload=New UpLoadClass
upload.MaxSize = 1048000
upload.FileType = "jpg/gif/png/bmp"
'上傳文件存放目錄
upload.SavePath = "Upfile/"
upload.open()

if upload.Error>0 then
response.write"<SCRIPT language=JavaScript>alert('上傳圖片只允許gif/jpg/png/bmp格式,且不能超過1MB。');"
response.write"javascript:history.go(-1)</SCRIPT>"
end if
'--上傳類函數結束--

set rs=server.createobject("adodb.recordset")
sql="select * from Table where...."
rs.open sql,conn,1,3
rs.addnew
'Pic為你上傳的圖片的提交名
rs("Pic")=upload.form("Pic")
'text為你提交的文本信息
rs("text")=upload.form("text")
rs....
rs.update
rs.close

10. HTML表單的POST上傳方式

是<form></form>之間的內容,例如:<form action="/search" name="search-form" method="post" id="search-form" class="search-form">,其中method就是上傳的方式。

熱點內容
查看linux所有用戶 發布:2024-10-26 14:11:15 瀏覽:15
useraddftp 發布:2024-10-26 13:59:21 瀏覽:621
安卓免費私密相冊哪個好用 發布:2024-10-26 13:41:20 瀏覽:639
湛江移動伺服器ip 發布:2024-10-26 13:12:17 瀏覽:634
找回dns伺服器地址 發布:2024-10-26 12:48:23 瀏覽:240
王者皮膚系統腳本 發布:2024-10-26 12:46:44 瀏覽:508
電腦配置8g怎麼查看 發布:2024-10-26 12:40:58 瀏覽:811
布朗編程 發布:2024-10-26 12:35:27 瀏覽:307
php平滑重啟 發布:2024-10-26 12:25:33 瀏覽:947
竹壓縮板材 發布:2024-10-26 12:21:32 瀏覽:754