ASPXはASPXページのファイルを非常に簡単に受け入れます。htmlinputfileを使用してください。問題ありませんが、htmlページの投稿ファイルを受け入れると
私はそれを自分でテストすることができるように、私はそれを共有できるようにするのは非常に簡単ではありません。
conmfig.xmlのファイルコンテンツ、タイプ、サイズ、カスタムストレージ位置
HTMLページのコンテンツ:( fckeditorから)
<html>
<head>
<title> fckeditor -uploadersテスト</title>
<スクリプト言語= "javascript">
関数sendfile()
{{
var suploaderurl = cmbuploaderurl.value;
if(suploaderurl.length == 0)
suploaderurl = txtcustomall.value;
if(suploaderurl.length == 0)
{{
アラート( 'カスタムURLを提供するか、デフォルトのURLを選択してください');
戻る;
}
Eurl.innerhtml = suploaderurl;
txturl.value = '';
frmupload.action = suploaderurl;
frmupload.submit();
}
function onuploadcompleted(errornumber、fileurl、filename、custmssg)
{{
スイッチ(erronumber)
{{
ケース0://エラーなし
txturl.value = fileurl;
Alert( 'エラーなしでアップロードされたファイル');
壊す;
ケース1://カスタムエラー
アラート(custmssg);
壊す;
ケース10://カスタム警告
txturl.value = fileurl;
アラート(custmssg);
壊す;
ケース201:
txturl.value = fileurl;
alert( '同じ名前のファイルがAlmedyが利用可能です。アップロードファイルは、「' + filename + '"'に変更されました);
壊す;
ケース202:
alert( 'invalid file');
壊す;
ケース203:
Alert( "セキュリティエラー。アップロードするのに十分な権限ではないでしょう。サーバーを確認してください。");
壊す;
デフォルト:
Alert( 'ファイルアップロードのエラー。Eric番号:' + errornumber);
壊す;
}
}
</script>
</head>
<body>
<Table CellSpacing = "0" CellPadding = "0">
<tr>
<td>
<Table CellSpacing = "0" CellPadding = "0">
<tr>
<td now4>
使用する「ファイルアップローダー」を選択します:<br>
<select id = "cmbuploaderurl" name = "select1">
<オプションselect value = "asp/upload.asp"> asp </option>
<オプション値= "php/upload.php"> php </option>
<オプション値= "upload.aspx?type = image"> aspx </option>
</select>
</td>
<TD Now&nbsp;
<td>
カスタムアップローダーURL:<br>
<入力ID = "txtcustomall" disabled type = "text">
</td>
</tr>
</table>
<br>
<Table CellSpacing = "0" CellPadding = "0">
<tr>
<td now4>
<form id = "frmupload"ターゲット= "uploadwindow" enctype = "multipart/form-data" action = "" method = "post">
新しいファイルをアップロード:<br>
<入力型= "ファイル" name = "newfile"> <br>
<入力型= "button" value = "サーバーに送信">
</form>
</td>
<td&nbsp;
<td value = "top">
アップロードされたファイルURL:<br>
<input id = "txturl" readonly type = "text">
</td>
</tr>
</table>
<br>
post url:<span id =&nbsp;
</td>
</tr>
<tr>
<td>
<ifme name = "uploadWindow"> </iframe>
</td>
</tr>
</table>
</body>
</html>
upload.aspxのコンテンツ:
<%@ページ言語= "c#" autoeventwireup = "true" codefile = "upload.aspx.cs" ensulits = "upload"%>%>
以下は背景コードです。
システムの使用。
System.Dataを使用しています。
System.Configurationを使用します。
System.Collectionsを使用します。
System.ioを使用しています。
System.textを使用しています。
system.webを使用しています。
system.web.securityを使用します。
system.web.uiを使用しています。
System.Web.ui.WebControlsを使用します。
System.web.ui.webcontrols.webpartsを使用します。
System.web.ui.htmlControlsを使用します。
System.xmlを使用しています。
System.Collections.Specializedを使用しています。
パブリック部分クラスのアップロード:System.Web.ui.page
{{
public void sendResults(int errornumber、string fileurl、string filename、string custommsg)
{{
stringbuilder text = new StringBuilder();
text.append( "<script type =/" text/javascript/">">);
Text.Append( "window.parent.onuploadcompleted(" + errorrnumber + "、/" + fileurl.replace( "/"、 "//" ")、/" + filename.replace( "/" "、" // /"") + "/"、/" + custommsg.replace("/""、 "//" ");/n");/n ");/n");/n ");/ n ");/n");/n ");/n");/n ");
text.append( "</script>");
respons.write(text.toString());
Response.End();
}
public void get getfig(string type、out string [] aut string [] denyedext、out long maxsize)、out long maxsize)
{{
xmldocumet doc = new xmldocument();
doc.load(server.mappath(@"./ config.xml");
xmlement root = doc.documentlement;
xmlnodelist imageexodelist = root.getElementsByTagname(タイプ);
adoverext = imagenodelist [0] .firstchild.innertext.trim();
denyedext = imagenodelist [0] .lastchild.innertext.trim();
savepath = root.getelementsbybytagname( "userpath").innertext.trim();
試す
{{
maxsize = convert.toint64(root.getelementsbytagname( "maxsize")。item(0).innertext.trim();););););););); ;);););)reeext.trim(););););););
}
catch {maxsize = 10*1024;}
}
保護されたvoid page_load(オブジェクト送信者、eventargs e)
{{
string [] adoverext = new String [] {}、denyedext = new String [] {};
文字列savepath = string.empty;
long maxsize = 10000;
string type = request.querystring ["type"];
if(type!= null && type!= string.empty)
type = type.tolower();
それ以外
type = "file";
if(type == "image")
{{
getConfig( "image"、out aot aladext、out denyedext、out savepath、out maxsize);
}
if(type == "file")
{{
getConfig( "file"、out autadext、out deenyedext、out savepath、out maxsize);
}
if(type == "flash"))
{{
getConfig( "flash"、out aotadext、out denyedext、out savepath、out maxsize);
}
ifpath == string.empty ||。
savepath = "〜/userfiles/";
if(!savepath.endswith( "/")savepath+= "/";
/******************************************* ** ***********************************
byte [] bytes1 = system.text.encoding.default.getBytes( "これは文字列/n/n/n/n");
byte [] bytes2 = new byte [] {1、33、23、3、0、56、55、235、5};
byte [] bytes = new byte [bytes1.length + bytes2.length];
//バイナリストリームをマージします
MemoryStream MS = new MemoryStream(バイト);
Ms.Write(bytes1、0、bytes1.length);
Ms.Write(bytes2、0、bytes2.length);
int count = 0、pos = 0;
// 4つの '/nを見つけ始めます'
for(int i = 0; i <bytes.length; i ++)
{{
if(bytes [i] ==(int) '/n')
{{
count ++;
if(count == 4)
{{
pos- = 4;
壊す;
}
}
}
if(count == 4)
{{
//ここで、バイトバイト配列の0からPOSへの位置は、必要な文字列です
// POS + 5の最初から最後まで、あなたが望むバイナリ
}
****************************************** **********************************
byte [] filedata、formdata;
formdata = request.binaryread(request.contentlength);
string head = string.empty;
エンコーディングencoding = encoding.utf8;
長いpos = 0;
for(long i = 0; i <formdata.longlength; i ++)
{{
if(formdata [i] ==(byte) '/r' && formdata [i + 1] ==(byte) '/n' && formdata [i + 2] ==(byte) '/r' && formdata [i + 3] ==(byte) '/n')
{{
pos = i;
壊す;
}
}
if(pos == 0){respons.end();
head = encoding.getString(formdata、0、(int)pos);
filedata = new byte [formdata.longlength -pos -3];
array.copy(formdata、pos + 4、filedata、0、formdata.longlength -pos -4);
/******************************************* ** **************************************** ***
//フォームの形式は次のとおりです。
// "--------------------------- 7D5FA3820F84/r/ncontent-disposition:form-data; name =/" newfile/ 「。
//後でファイルデータです
****************************************** ******************************************** ***********
head = head.tolower();
head = head.remove(0、head.indexof( "/r/n");
head = head.replace( "/" "、" ");
文字列postfileName = string.Empty;
文字列ファイル名
String filetype、fileext;
PostFileName = head.Substring(0、head.indexof( "/r/n"); // content-disposition:form-data; name =/"newfile/"; 4(10995).jpg/"
filetype = head.remove(0、postfilename.length + 3);
PostFileName = PostFileName.Substring(POSTFILENAME.INDEXOF( "filename =") + "filename ="
filename = path.getFileName(postFileName);
filext = filename.substring(filename.lastindexof( "。") + 1;
ifdata.longlength> maxsize {{{
SendResults(2、Resolveurl(SavePath + Filename)、Filename、 "Too Gorge");
戻る;
}
bool isallow = false;
foreach(denyedextの文字列ext){
if(ext == fileext){
isallow = false;
SendResults(202、Resolveurl(SavePath + Filename)、Filename、 "Forbiden");
戻る;
}
}
foreach(string ext in aowext){{
if(ext == fileext){isallow = true;}
}
if(isallow)
{{
string tmppath = server.mappath(savepath);
if(!directory.exists(tmppath)){{
試す
{{
directory.createdirectory(tmppath);
}
catch {sendResults(200、resolveurl(savepath + filename)、filename、 "no write permissions");}
}
//response.binarywrite(filedata);
FileStream SaveFilestream = new FileStream(TMPPATH+FILENAME、FILEMODE.OPENORCREATE、FILEACCESS.READWRITE);
for(long i = 0; i <fledata.longlength; i ++)
{{
savefilestream.writebyte(filedata [i]);
}
savefilestream.close();
SendResults(0、Resolveurl(SavePath + Filename)、Filenamame、 "Errors no");
}
}
}
config.xml
<?xmlバージョン= "1.0" encoding = "utf-8"?>
<アップロード>
<Evabled> true </enabled>
<userpath> </userpath>
<maxsize> 500000 </maxsize> <! - ユニットはbyte->です
<file>
<low> zip |
<php5 |
</file>
<image>
<aplate> gif |
<deny> </deny>
</image>
<flash>
<lows> swf |
<deny> </deny>
</flash>
</upload>