ASPX aceita o arquivo da página ASPX é muito simples, basta usar htmlinputfile, tudo bem, mas se você aceitar o arquivo de postagem da página html
Não é muito fácil de lidar.
Conteúdo do arquivo, tipo, tamanho, posição de armazenamento personalizado, em Conmfig.xml
Conteúdo da página HTML: (da fckeditor)
<html>
<head>
<title> fckeditor -Uploaders testes </ititle>
<Script Language = "JavaScript">
Função sendfile ()
{{
var suploaderurl = cmbuploaderurl.value;
If (suploaderurl.length == 0)
suploaderurl = txtCustomall.value;
If (suploaderurl.length == 0)
{{
Alerta ('forneça seu URL personalizado ou selecione um padrão');
Retornar;
}
EURL.innerhtml = suploaderurl;
txturl.value = '';
frmupload.action = suploaderurl;
frmupload.submit ();
}
Função onuploadcompleted (errornumber, fileurl, nome do arquivo, custmssg)
{{
Switch (errornumber)
{{
Caso 0: // Sem erros
txturl.value = fileurl;
Alert ('arquivo enviado sem erro');
Quebrar;
Caso 1: // Erro personalizado
Alerta (custmssg);
Quebrar;
Caso 10: // Aviso personalizado
txturl.value = fileurl;
Alerta (custmssg);
Quebrar;
Caso 201:
txturl.value = fileurl;
Alert ('um arquivo com o mesmo nome está almedy disponível. O arquivo de upload foi renomeado para "' + nome do arquivo + '"');
Quebrar;
Caso 202:
Alerta ('arquivo inválido');
Quebrar;
Caso 203:
Alerta ("Erro de segurança. Você provavelmente não não não é o suficiente para fazer o upload. Verifique seu servidor.");
Quebrar;
PADRÃO:
alerta ('erro no upload do arquivo. Número ERIC:' + errornumber);
Quebrar;
}
}
</script>
</head>
<Body>
<Tabela CellSpacing = "0" CellPadding = "0">
<tr>
<Td>
<Tabela CellSpacing = "0" CellPadding = "0">
<tr>
<Td agora4>
Selecione o "uploader de arquivo" para usar: <br>
<select id = "cmbuploaderurl" name = "select1">
<opção selecione value = "asp/upload.asp"> asp </pption>
<opção value = "php/upload.php"> php </pption>
<opção value = "upload.aspx? type = imagem"> aspx </pption>
</leclect>
</td>
<Td agora44 & nbsp;
<Td>
URL do upload personalizado: <br>
<input id = "txtCustomall" desativado type = "text">
</td>
</tr>
</tabela>
<br>
<Tabela CellSpacing = "0" CellPadding = "0">
<tr>
<Td agora4>
<Form id = "frmupload" target = "uploadwindow" ENCTYPE = "Multipart/form-data" action = "" Method = "post">>
Carregue um novo arquivo: <br>
<input type = "file" name = "newfile"> <br>
<input type = "button" value = "Envie -o para o servidor">
</morm>
</td>
<Td> & nbsp;
<td value = "top">
URL do arquivo carregado: <br>
<input id = "txturl" readonly type = "text">
</td>
</tr>
</tabela>
<br>
Post URL: <span id = "EURL"> & nbsp;
</td>
</tr>
<tr>
<Td>
<ifme name = "uploadwindow"> </frame>
</td>
</tr>
</tabela>
</body>
</html>
Conteúdo do upload.aspx:
<%@ página de página = "c#" autoeventwireup = "true" codefile = "upload.aspx.cs" herits = "upload"%>%>
A seguir, o código de fundo:
usando o sistema;
usando System.data;
usando System.Configuration;
usando System.Collections;
usando System.io;
usando System.Text;
usando System.Web;
Usando o System.Web.Security;
usando system.web.ui;
usando o System.web.ui.webcontrols;
usando o System.web.ui.webcontrols.webparts;
usando o System.web.ui.htmlControls;
usando System.xml;
Usando System.Collection.Specialized;
Upload de classe parcial pública: 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>");
Response.Write (text.toString ());
resposta.END ();
}
Public void get getfig (tipo de string, out string [] allowext, out string [] nenyedext, fora do maxsize longo), fora do maxSize longo)
{{
xmldocumet doc = new xmldocument ();
doc.load (server.mappath (@"./ config.xml");
Xmlement root = doc.documentElement;
Xmlnodelist imageExodelist = root.getElementsByTagName (tipo);
Perlandeext = imagenodelist [0] .firstchild.innertext.trim ().
Denyedext = Imagenodelist [0] .LastChild.innerText.Trim ().
SavePath = root.getElementsByByTagName ("UserPath").
tentar
{{
maxsize = convert.toint64 (root.getElementsByTagName ("maxsize"). Item (0) .innerText.Trim ()););););););););); ;);););););) Reeext.trim ()););););););););););
}
Catch {maxSize = 10*1024;}
}
Void Page_load protegido (remetente de objeto, EventArgs e)
{{
String [] alloweDext = new String [] {}, Denyedext = new String [] {};
String savePath = string.Empty;
maxSize longo = 10000;
string type = request.QueryString ["type"];
if (type! = null && type! = string.empty)
Type = type.Tolower ();
outro
type = "arquivo";
if (tipo == "imagem")
{{
getConfig ("Image", Out AllowExt, Out Denyedext, Out SavePath, Out MaxSize);
}
if (tipo == "arquivo")
{{
getConfig ("FILE", Out WhiteDext, Out Deenyedext, Out SavePath, Out MaxSize);
}
if (tipo == "flash"))
{{
getConfig ("Flash", Out AllowExt, Out Denyedext, Out SavePath, Out MaxSize);
}
ifPath == String.Empty || SavePath == "")
savePath = "~/userfiles/";
if (! salvath.endswith ("/") salvath+= "/";
/***************************************************** ** ***************************************
byte [] bytes1 = system.text.encoding.default.getbytes ("Esta é uma string/n/n/n/n");
byte [] bytes2 = novo byte [] {1, 33, 23, 3, 0, 56, 55, 235, 5};
byte [] bytes = novo byte [bytes1.length + bytes2.Length];
// Mesclar fluxo binário
MemoryStream ms = new MemoryStream (bytes);
ms.write (bytes1, 0, bytes1.length);
srs.write (bytes2, 0, bytes2.Length);
int count = 0, pos = 0;
// Comece a encontrar quatro '/n'
for (int i = 0; i <bytes.length; i ++)
{{
if (bytes [i] == (int) '/n')
{{
Contagem ++;
if (count == 4)
{{
Pos- = 4;
Quebrar;
}
}
}
if (count == 4)
{{
// aqui, a posição de 0 a POS na matriz de bytes é a string que você deseja
// Desde o início do POS + 5 até o fim, o binário que você deseja
}
**************************************************** ********************************************
byte [] arquivado, formData;
FormData = request.binaryRead (request.contentLength);
String head = string.empty;
codificação codinging = coding.utf8;
POS longo = 0;
para (longo 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;
Quebrar;
}
}
if (pos == 0) {Response.end ();
cabeça = coding.getString (formData, 0, (int) pos);
Filedata = novo byte [formData.longLength -pos -3];
Array.copy (formData, pos + 4, arquivado, 0, formData.longLength -pos -4);
/***************************************************** ** ************************************************** ***
// A forma do formulário vem é:
// "----------------------------- 7D5FA3820F84/R/NCONTENT-DISPOSIÇÃO: FORM-DATA; NAME =/" NEWFILE/ ".
// posterior é os dados do arquivo
**************************************************** **************************************************** *************
cabeça = head.tolower ();
Head = Head.Remove (0, Head.IndexOF ("/R/N");
Head = Head.Replace ("/" "," ");
String postFilename = String.Empty;
nome do arquivo de string;
string filetype, fileExt;
PostFilename = head.substring (0, head.indexOF ("/r/n"); // content-Disposition: form-data; nome =/"newFile/"; 4 (10995) .jpg/"
Filetype = Head.Remove (0, PostFileName.Length + 3);
PostFilename = PostFileName.substring (PostFileName.indexof ("FileName =") + "FileName =". Length);
FILENAME = PATH.GETFILENAME (PostFileName);
filext = filename.substring (filename.lastIndexOF (".") + 1;
ifdata.longlength> maxsize {{
SendResults (2, Resolveurl (SalvePath + FileName), nome do arquivo, "muito grande");
Retornar;
}
Bool isallow = false;
Foreach (string ext em nenyedext) {
if (ext == FileExt) {
Isallow = false;
SendResults (202, Resolveurl (SalvePath + FileName), nome do arquivo, "Forneden");
Retornar;
}
}
Foreach (string ext em allowext) {{
if (ext == fileExt) {isallow = true;
}
se (isallow)
{{
string tmppath = server.mappath (savePath);
if (! diretório.exists (tmppath)) {{
tentar
{{
Diretório.createDirectory (tmppath);
}
Catch {SendResults (200, Resolveurl (SalvePath + FileName), nome do arquivo, "sem permissões de gravação");}
}
//Response.binaryWrite (FileData);
FileStream SaveFileStream = novo FileStream (tmppath+FileName, filemode.openorCreate, FileAccess.readWrite);
para (long i = 0; i <flaData.longLength; i ++)
{{
saveFileStream.WriteByte (FileData [i]);
}
saveFileStream.close ();
SendResults (0, Resolveurl (SalvePath + FileName), FILENAMAME, "SEM ERROS");
}
}
}
config.xml
<? xml versão = "1.0" coding = "utf-8"?
<Opload>
<Vabled> true </ilabled>
<veserPath> </astarpath>
<TaxSize> 500000 </sAxSize> <!-unidade é byte->
<File>
<Permitir> Zip |
<Deny> php |
</file>
<Imagem>
<Permitir> JPG |
<neny> </nyy>
</image>
<flash>
<Permitir> SWF |
<neny> </nyy>
</flash>
</upload>