ASPX acepta que el archivo de la página ASPX es muy simple, solo use htmlinputfile, está bien, pero si acepta el archivo de publicación de la página HTML
No es muy fácil de manejar.
Contenido de archivo, tipo, tamaño, posición de almacenamiento personalizado, en Conmfig.xml
Contenido de la página HTML: (desde FCKEditor)
<html>
<Evista>
<title> fcKeditor -Upploaders prueba </title>
<script language = "javaScript">
Función sendFile ()
{{
var suploaderurl = cmbuploaderurl.value;
If (suploaderurl.length == 0)
suploaderurl = txtcustomall.value;
If (suploaderurl.length == 0)
{{
Alerta ('Proporcione su URL personalizada o seleccione una predeterminada');
Devolver;
}
eurl.innerhtml = suploaderurl;
txturl.value = '';
frmupload.action = suploaderurl;
frmupload.submit ();
}
Función onUploadCompleted (Errornumber, FileUrl, FileName, CustmsSG)
{{
Switch (Errornumber)
{{
Caso 0: // Sin errores
txturl.value = fileUrl;
Alerta ('Archivo cargado sin error');
Romper;
Caso 1: // Error personalizado
Alerta (custmssg);
Romper;
Caso 10: // Advertencia personalizada
txturl.value = fileUrl;
Alerta (custmssg);
Romper;
Caso 201:
txturl.value = fileUrl;
Alerta ('un archivo con el mismo nombre está disponible a Almedy. El archivo de carga ha cambiado a Ben a "' + FileName + '" ");
Romper;
Caso 202:
Alerta ('archivo no válido');
Romper;
Caso 203:
Alerta ("Error de seguridad. Probablemente no pueda no poder no poder.
Romper;
POR DEFECTO:
alerta ('Error en la carga de archivo. Número Eric:' + Errornumber);
Romper;
}
}
</script>
</ablo>
<Body>
<TABLE CELLSPACING = "0" CellPadding = "0">
<tr>
<TD>
<TABLE CELLSPACING = "0" CellPadding = "0">
<tr>
<Td Now4>
Seleccione el "Alcance de archivos" para usar: <br>
<select id = "cmbuploaderurl" name = "select1">
<opción select value = "ASP/upload.asp"> ASP </opción>
<opción valor = "php/upload.php"> php </opción>
<option value = "upload.aspx? type = image"> aspx </option>
</select>
</td>
<Td now44 & nbsp;
<TD>
URL de cargador personalizado: <br>
<input id = "txtcustomall" discapacitado type = "text">
</td>
</tr>
</table>
<br>
<TABLE CELLSPACING = "0" CellPadding = "0">
<tr>
<Td Now4>
<Form ID = "FRMUPLOAD" Target = "uploadwindow" enctype = "multipart/form-data" action = "" método = "post">
Sube un nuevo archivo: <br>
<input type = "file" name = "newfile"> <br>
<input type = "button" value = "Enviarlo al servidor">
</form>
</td>
<Td> & nbsp;
<td value = "top">
URL de archivo cargado: <br>
<input id = "txturl" readonly type = "text">
</td>
</tr>
</table>
<br>
Post URL: <span id = "eurl"> & nbsp;
</td>
</tr>
<tr>
<TD>
<ifMe name = "uploadwindow"> </iframe>
</td>
</tr>
</table>
</body>
</html>
Contenido de carga.aspx:
<%@ page lenguaje = "c#" autoeventwireUp = "true" codeFile = "upload.aspx.cs" heredes = "cargar"%>%>
El siguiente es el código de fondo:
usando el sistema;
usando System.Data;
utilizando System.Configuración;
usando System.Collections;
usando System.io;
usando System.Text;
usando System.web;
Usando System.Web.Security;
usando System.web.ui;
usando System.Web.UI.WebControls;
usando System.web.ui.webcontrols.webparts;
usando System.Web.UI.HTMLControls;
usando System.xml;
Usando System.Collections.pecialized;
Carga de clase 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>");
respuesta.write (text.toString ());
respuesta.end ();
}
Public void get getFig (tipo de cadena, string string [] permitidoxt, out string [] denyEnext, out long maxsize), out largo maxsize)
{{
xmlDocumet doc = new xmlDocument ();
doc.load (server.mappath (@"./ config.xml");
xmlement root = doc.DocumentElement;
XmlnodeList imageExodeList = root.getElementsByTagName (type);
Permitido = imageDelist [0] .FirstChild.inntext.trim ().
DenyExt = ImageDelist [0] .lastchild.inntext.trim ().
savePath = root.getElementsByByTagName ("UserPath").
intentar
{{
maxSize = Convert.Toint64 (root.getElementsByTagName ("maxSize"). item (0) .inntext.trim ());););););); ;););););
}
Catch {maxSize = 10*1024;}
}
Protegido void page_load (remitente de objeto, EventArgs e)
{{
String [] permitidoxt = new String [] {}, DenyEnext = new String [] {};
string savePath = string.empty;
largo maxSize = 10000;
string type = request.queryString ["type"];
if (type! = null && type! = string.empty)
Type = type.tolower ();
demás
type = "archivo";
if (type == "imagen")
{{
getConfig ("Image", Out ElExtExt, Out DenyedExt, Out SavePath, Out MaxSize);
}
if (type == "archivo")
{{
getConfig ("file", out le permitedext, out deenyedext, out savePath, out maxsize);
}
if (type == "flash"))
{{
getConfig ("flash", out le permitedext, out denyedExt, out savePath, out maxsize);
}
ifpath == String.empty ||
SavePath = "~/UserFiles/";
if (! SavePath.endswith ("/") SavePath+= "/";
/****************************************************** ** ******************************************
byte [] bytes1 = system.text.encoding.default.getBytes ("Esta es una cadena/n/n/n/n");
byte [] bytes2 = nuevo byte [] {1, 33, 23, 3, 0, 56, 55, 235, 5};
byte [] bytes = new byte [bytes1.length + bytes2.length];
// Fusionar transmisión binaria
MemoryStream MS = new MemoryStream (bytes);
ms.write (bytes1, 0, bytes1.length);
ms.write (bytes2, 0, bytes2.length);
int count = 0, pos = 0;
// Empiece a buscar cuatro '/n'
para (int i = 0; i <bytes.length; i ++)
{{
if (bytes [i] == (int) '/n')
{{
Contar ++;
if (count == 4)
{{
Pos- = 4;
Romper;
}
}
}
if (count == 4)
{{
// Aquí, la posición de 0 a POS en la matriz de bytes de bytes es la cadena que desea
// Desde el comienzo de POS + 5 hasta el final, el binario que desea
}
*********************************************** ********************************************
byte [] fileData, formData;
Formdata = request.binaryRead (request.contentLength);
String head = string.empty;
codificación codificación = coding.utf8;
largo pos = 0;
para (largo 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;
Romper;
}
}
if (pos == 0) {respuesta.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);
/****************************************************** ** ******************************************************** ***
// La forma de la forma viene es:
// "----------------------- ".
// Más tarde son los datos del archivo
*********************************************** ************************************************************ ***********
head = head.tolower ();
head = head.remove (0, head.indexof ("/r/n");
head = head.replace ("/" "," ");
cadena postfileName = string.empty;
Nombre de archivo de cadena;
String fileType, fileext;
PostfileName = head.substring (0, head.indexof ("/r/n"); // content-disisposition: form-data; name =/"newfile/"; 4 (10995) .jpg/"
fileType = head.remove (0, postfileName.length + 3);
PostFileName = PostFileName.Substring (PostFileName.IndexOf ("FileName =") + "FileName =". Longitud);
FileName = Path.getFileName (PostFileName);
filext = filename.substring (filename.lastIndexOf (".") + 1;
ifdata.longLength> maxSize {{
SendResults (2, resolveUrl (savePath + nombre de archivo), nombre de archivo, "demasiado grande");
Devolver;
}
Bool islow = false;
Foreach (string ext en denyedExt) {
if (ext == fileext) {
Islow = false;
SendResults (202, resolveUrl (savePath + nombre de archivo), nombre de archivo, "prohibido");
Devolver;
}
}
Foreach (string ext en tarloxt) {{
if (ext == fileext) {isAllow = true;
}
if (islow)
{{
cadena tmppath = server.mappath (savePath);
if (! Directory.exists (tmppath)) {{
intentar
{{
Directorio.createDirectory (tmppath);
}
Catch {sendResults (200, resolveUrl (savePath + nombre de archivo), nombre de archivo, "sin permisos de escritura");}
}
//Response.BinaryWrite (fileData);
FileStream SaveFiLEnstream = new FilErteam (tmppath+nombre de archivo, fileMode.openorcreate, fileAccess.readWrite);
para (largo i = 0; i <fledata.longlength; i ++)
{{
SaveFilErteam.writyte (fileData [i]);
}
SaveFilErteam.Close ();
SendResults (0, resolveUrl (savePath + nombre de archivo), filenamame, "sin errores");
}
}
}
config.xml
<? Versión XML = "1.0" Coding = "UTF-8"?>
<Cuber>
<Evaped> true </kable>
<SererPath> </serPath>
<AmxSize> 500000 </aMaxSize> <!-Unidad es byte->
<Archivo>
<permitirse> zip |
<DeMe> Php5 |
</archivo>
<Imagen>
<permitirse> jpg |
<enyy> </negy>
</Image>
<Sphsh>
<permitirse> swf |
<enyy> </negy>
</shash>
</lowload>