选择显示字体大小

使aspx页面能接受html,asp的页面传送的文件

 aspx接受aspx页面的文件很简单,用htmlinputfile,就可以了,但是如果接受html页面post的文件
就不怎么好办了,我仿照asp的方法做法如下,自己测试通过,拿出来给大家共享,可以限制
文件内容,类型,大小,自定义存储位置,在congfig.xml
html页的内容:(来自fckeditor)
<html>
 <head>
  <title>fckeditor - uploaders tests</title>
  <script language="javascript">

function sendfile()
{
 var suploaderurl = cmbuploaderurl.value ;
 
 if ( suploaderurl.length == 0 )
  suploaderurl = txtcustomurl.value ;
 
 if ( suploaderurl.length == 0 )
 {
  alert( 'please provide your custom url or select a default one' ) ;
  return ;
 }
 
 eurl.innerhtml = suploaderurl ;
 txturl.value = '' ;
 
 frmupload.action = suploaderurl ;
 frmupload.submit() ;
}

function onuploadcompleted( errornumber, fileurl, filename, custommsg )
{
 switch ( errornumber )
 {
  case 0 : // no errors
   txturl.value = fileurl ;
   alert( 'file uploaded with no errors' ) ;
   break ;
  case 1 : // custom error
   alert( custommsg ) ;
   break ;
  case 10 : // custom warning
   txturl.value = fileurl ;
   alert( custommsg ) ;
   break ;
  case 201 :
   txturl.value = fileurl ;
   alert( 'a file with the same name is already available. the uploaded file has been renamed to "' + filename + '"' ) ;
   break ;
  case 202 :
   alert( 'invalid file' ) ;
   break ;
  case 203 :
   alert( "security error. you probably don't have enough permissions to upload. please check your server." ) ;
   break ;
  default :
   alert( 'error on file upload. error number: ' + errornumber ) ;
   break ;
 }
}

  </script>
 </head>
 <body>
  <table cellspacing="0" cellpadding="0" width="100%" border="0" height="100%">
   <tr>
    <td>
     <table cellspacing="0" cellpadding="0" width="100%" border="0">
      <tr>
       <td nowrap style="height: 43px">
        select the "file uploader" to use:<br>
        <select id="cmbuploaderurl" name="select1">
         <option selected value="asp/upload.asp">asp</option>
         <option value="php/upload.php">php</option>
         <option value="upload.aspx?type=image">aspx</option>
        </select>
       </td>
       <td nowrap style="height: 43px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
       <td width="100%" style="height: 43px">
        custom uploader url:<br>
        <input id="txtcustomurl" style="width: 100%; background-color: #dcdcdc" disabled type="text">
       </td>
      </tr>
     </table>
     <br>
     <table cellspacing="0" cellpadding="0" width="100%" border="0">
      <tr>
       <td nowrap>
        <form id="frmupload" target="uploadwindow" enctype="multipart/form-data" action="" method="post">
         upload a new file:<br>
         <input type="file" name="newfile"><br>
         <input type="button" value="send it to the server" onclick="sendfile();">
        </form>
       </td>
       <td style="width: 16px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
       <td valign="top" width="100%">
        uploaded file url:<br>
        <input id="txturl" style="width: 100%" readonly type="text">
       </td>
      </tr>
     </table>
     <br>
     post url: <span id="eurl">&nbsp;</span>
    </td>
   </tr>
   <tr>
    <td height="100%">
     <iframe name="uploadwindow" width="100%" height="100%"></iframe>
    </td>
   </tr>
  </table>
 </body>
</html>
upload.aspx的内容:
<%@ page language="c#" autoeventwireup="true"  codefile="upload.aspx.cs" inherits="upload"%>
下面是后台代码:
using system;
using system.data;
using system.configuration;
using system.collections;
using system.io;
using system.text;
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.xml;
using system.collections.specialized;
public partial class upload : 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(" + errornumber + ",\"" + fileurl.replace("\"", "\\\"") + "\",\"" + filename.replace("\"", "\\\"") + "\",\"" + custommsg.replace("\"", "\\\"") + "\") ;\n");
  text.append(" </script>");
  response.write(text.tostring());
  response.end();
 }
 public void getconfig(string type, out string[] allowedext, out string[] denyedext,out string savepath,out long maxsize)
 {
   xmldocument doc = new xmldocument();
   doc.load(server.mappath(@".\config.xml"));
   xmlelement root=doc.documentelement;
   xmlnodelist imagenodelist=root.getelementsbytagname(type);
   allowedext = imagenodelist[0].firstchild.innertext.trim().split('');
   denyedext = imagenodelist[0].lastchild.innertext.trim().split('');
   savepath = root.getelementsbytagname("userpath").item(0).innertext.trim();
   try
   {
    maxsize = convert.toint64(root.getelementsbytagname("maxsize").item(0).innertext.trim());
   }
   catch { maxsize = 10*1024; }
 }
 protected void page_load(object sender, eventargs e)
 {

  string[] allowedext = new string[] { }, denyedext = new string[] { };
  string savepath = string.empty;
  long maxsize = 10000;
  string type = request.querystring["type"];
  if(type!=null&&type!=string.empty)
   type=type.tolower();
  else
   type="file";
  if (type == "image")
  {
   getconfig("image", out allowedext, out denyedext, out savepath,out maxsize);   
  }
  if (type == "file")
  {
   getconfig("file", out allowedext, out denyedext, out savepath, out maxsize);   
  }
  if (type == "flash")
  {
   getconfig("flash", out allowedext, out denyedext, out savepath, out maxsize);  
  }
  if (savepath == string.emptysavepath=="")
   savepath = "~/userfiles/";
  if(!savepath.endswith("/"))savepath+="/";

本新闻共2


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons