上傳檔案(限制檔案型別)

2021-04-19 22:43:27 字數 1915 閱讀 3434

1,fileupload.aspx檔案

<%@ page language="c#" autoeventwireup="true" codefile="fileupload.aspx.cs" inherits="fileupload" %>

2、fileupload.aspx.cs檔案

using system;

using system.data;

using system.configuration;

using system.collections;

using system.web;

using system.web.security;

using system.web.ui;

using system.web.ui.webcontrols;

using system.web.ui.webcontrols.webparts;

using system.web.ui.htmlcontrols;

using system.data.sqlclient;

using system.io;

using system.text;

public partial class fileupload : system.web.ui.page

///

/// 上傳

///

///

///

protected void btnsubmit_click(object sender, eventargs e)

private void writerstream()

int intdoclen = txtfilecontents.postedfile.contentlength;           //獲取上傳檔案大小

byte docbuffer = new byte[intdoclen];

stream objstream = txtfilecontents.postedfile.inputstream;         

objstream.read(docbuffer, 0, intdoclen);                        //以流的形式讀取上傳檔案

using (sqlconnection con = new sqlconnection(conne))            //資料庫連線

else}}

}}}}

3、usp_booksuploadfile儲存過程

use [test]

go/****** 物件:  storedprocedure [dbo].[usp_booksuploadfile]    指令碼日期: 08/29/2008 17:02:29 ******/

set ansi_nulls on

goset quoted_identifier on

goalter procedure [dbo].[usp_booksuploadfile]

@title varchar(200),

@doc image,

@doctype varchar(4)

asinsert tblbooksupload(doctitle,doc,doctype) values (@title,@doc,@doctype)

4、tblbooksupload表

use test

gocreate table tblbooksupload(

docid int identity primary key,

doctitle nvarchar(200),

doc image,

doctype nvarchar(50),

entrydate datetime        )go

5.建立資料庫test

create database test

go

input 限制 上傳檔案型別

tr tdcolspan 5 款式 inputtype file accept image name img id img td tr tr tdcolspan 2 作業指導書 inputtype file accept name work attach id work attach td tdco...

input file控制項限制上傳檔案型別

inputclass file type file 預設是這樣的,所有檔案型別都會顯示出來,如果想限制它只顯示我們設定的檔案型別呢,比如 excel pdf 檔案 inputclass file type file accept xls,pdf 但是這算不上嚴格意義上的限制,只是把你要的檔案型別預設...

input file控制項限制上傳檔案型別

網頁上新增乙個input file html控制項 預設是這樣的,所有檔案型別都會顯示出來,如果想限制它只顯示我們設定的檔案型別呢,比如 word excel pdf 檔案 解決辦法是可以給它新增乙個accept屬性,比如 附支援的檔案型別 but,這只是最簡單的掩人耳目的做法,還是能選擇其它檔案型...