请教问题

来源:互联网 发布:seo与sem区别 编辑:程序博客网 时间:2024/05/01 03:02

请教一下 我是用DW的图片上传插件 可是上传后没有显示图片地址 那位高人能不能改改 显示地址在一个文本框里呀

上传页
<form id="form1" name="form1" method="post" action="">
  <p><img src="icon_prev.gif" alt="图片预览" name="showImg" id="showImg">
    <input type="button" name="Submit" value="上传" onClick="window.open('fupload.asp?useForm=form1&amp;prevImg=showImg&amp;upUrl=&amp;ImgS=400&amp;ImgW=&amp;ImgH=&amp;reItem=rePic','fileUpload','width=400,height=180')">
    <input name="rePic" type="hidden" id="rePic" size="4">
</p>
  <p>
    <label>
    <input type="text" name="textfield" />
    </label>
</p>
</form>

fupaction.asp文件

<%
Dim FormData, FormSize, Divider, bCrLf
FormSize = Request.TotalBytes
FormData = Request.BinaryRead(FormSize)
bCrLf = ChrB(13) & ChrB(10)
Divider = LeftB(FormData, InStrB(FormData, bCrLf) - 1)

Function SaveFile(FormFileField, Path, SavType)
    Dim StreamObj,StreamObj1
    Set StreamObj = Server.CreateObject("ADODB.Stream")
    Set StreamObj1 = Server.CreateObject("ADODB.Stream")
    StreamObj.Mode = 3
    StreamObj1.Mode = 3
    StreamObj.Type = 1
    StreamObj1.Type = 1
    SaveFile = ""
    StartPos = LenB(Divider) + 2
    FormFileField = Chr(34) & FormFileField & Chr(34)
    If Right(Path,1) <> "/" Then
        Path = Path & "/"
    End If
    Do While StartPos > 0
        strlen = InStrB(StartPos, FormData, bCrLf) - StartPos
        SearchStr = MidB(FormData, StartPos, strlen)
        If InStr(bin2str(SearchStr), FormFileField) > 0 Then
            FileName = bin2str(GetFileName(SearchStr,path,SavType))
            If FileName <> "" Then
                FileStart = InStrB(StartPos, FormData, bCrLf & bCrLf) + 4
                FileLen = InStrB(StartPos, FormData, Divider) - 2 - FileStart
                FileContent = MidB(FormData, FileStart, FileLen)
                StreamObj.Open
                StreamObj1.Open
                StreamObj.Write FormData
                StreamObj.Position=FileStart-1
                StreamObj.CopyTo StreamObj1,FileLen
                If SavType =0 Then
                   SavType = 1
                End If
                StreamObj1.SaveToFile Path & FileName, SavType
                StreamObj.Close
    StreamObj1.Close
                If SaveFile <> "" Then
                    SaveFile = SaveFile & ","  & FileName
                Else
                    SaveFile = FileName
                End If
            End If
        End If
        If InStrB(StartPos, FormData, Divider) < 1 Then
           Exit Do
        End If
        StartPos = InStrB(StartPos, FormData, Divider) + LenB(Divider) + 2
    Loop
End Function

Function GetFormVal(FormName)
    GetFormVal = ""
    StartPos = LenB(Divider) + 2
    FormName = Chr(34) & FormName & Chr(34)
    Do While StartPos > 0
        strlen = InStrB(StartPos, FormData, bCrLf) - StartPos
        SearchStr = MidB(FormData, StartPos, strlen)
        If InStr(bin2str(SearchStr), FormName) > 0 Then
               ValStart = InStrB(StartPos, FormData, bCrLf & bCrLf) + 4
               ValLen = InStrB(StartPos, FormData, Divider) - 2 - ValStart
                  ValContent = MidB(FormData, ValStart, ValLen)
               If GetFormVal <> "" Then
                GetFormVal = GetFormVal & "," & bin2str(ValContent)
            Else
                GetFormVal = bin2str(ValContent)
            End If
        End If
        If InStrB(StartPos, FormData, Divider) < 1 Then
            Exit Do
        End If
        StartPos = InStrB(StartPos, FormData, Divider) + LenB(Divider) + 2
    Loop
End Function

Function bin2str(binstr)
   Dim varlen, clow, ccc, skipflag
   skipflag = 0
   ccc = ""
   varlen = LenB(binstr)
   For i = 1 To varlen
       If skipflag = 0 Then
          clow = MidB(binstr, i, 1)
           If AscB(clow) > 127 Then
             ccc = ccc & Chr(AscW(MidB(binstr, i + 1, 1) & clow))
             skipflag = 1
          Else
             ccc = ccc & Chr(AscB(clow))
          End If
       Else
          skipflag = 0
       End If
   Next
   bin2str = ccc
End Function

Function str2bin(str)
    For i = 1 To Len(str)
        str2bin = str2bin & ChrB(Asc(Mid(str, i, 1)))
    Next
End Function

Function GetFileName(str,path,savtype)
    Set fs = Server.CreateObject("Scripting.FileSystemObject")
    str = RightB(str,LenB(str)-InstrB(str,str2bin("filename="))-9)
    GetFileName = ""
    FileName = ""
    For i = LenB(str) To 1 Step -1
        If MidB(str, i, 1) = ChrB(Asc("/")) Then
            FileName = MidB(str, i + 1, LenB(str) - i - 1)
            Exit For
        End If
    Next
    If savtype = 0 and fs.FileExists(path & bin2str(FileName)) = True Then
        hFileName = FileName
        rFileName = ""
        For i = LenB(FileName) To 1 Step -1
            If MidB(FileName, i, 1) = ChrB(Asc(".")) Then
                hFileName = LeftB(FileName, i-1)
                rFileName = RightB(FileName, LenB(FileName)-i+1)
                Exit For
            End If
        Next
           For i = 0 to 9999
               If fs.FileExists(path & bin2str(hFileName) & i & bin2str(rFileName)) = False Then
                   FileName = hFileName & str2bin(i) & rFileName
                   Exit For
              End If
           Next
       End If
       Set fs = Nothing
       GetFileName = FileName
End Function
%>
<%
 dim upfilename
 upUrl = GetFormVal("upUrl")
 prevImg = GetFormVal("prevImg")
 reItem = GetFormVal("reItem")
 useForm = GetFormVal("useForm")
 path = Server.MapPath(upUrl)
 upfilename = SaveFile("upfile",path,0)
%>
<script language = "JavaScript">
window.opener.<%=useForm%>.<%=prevImg%>.src = '<%=upUrl%>'+'/'+'<%=upfilename%>';
window.opener.<%=useForm%>.<%=reItem%>.value = '<%=upfilename%>';
window.close();
</Script>

fupload.asp文件

<%@LANGUAGE="VBSCRIPT" CODEPAGE="950"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传系统</title>
<script language="JavaScript">
<!--
//检查上传物件 checkFileUpload(表单名称,档案类型,是否需要上传,档案大小,图片最小宽度,图片最小高度,图片最大宽度,图片最大高度,储存宽度的表单名称,储存高度的表单名称)
function checkFileUpload(form,extensions,requireUpload,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) {
  document.MM_returnValue = true;
  if (extensions != '') var re = new RegExp("/.(" + extensions.replace(/,/gi,"|") + ")$","i");
  for (var i = 0; i<form.elements.length; i++) {
    field = form.elements[i];
    if (field.type.toUpperCase() != 'FILE') continue;
    if (field.value == '') {
      if (requireUpload) {alert('请选取上传的档案!');document.MM_returnValue = false;field.focus();break;}
    } else {
      if(extensions != '' && !re.test(field.value)) {
        alert('这个档案不符合上传的类型!/n只有以下的类型才允许上传: ' + extensions + '。/n请依规定选取新的档案。');
        document.MM_returnValue = false;field.focus();break;
      }
    document.PU_uploadForm = form;
    re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");
    if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
      setTimeout('if (document.MM_returnValue) document.PU_uploadForm.submit()',500);
      checkImageDimensions(field.value,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight);
    } } }
}

function showImageDimensions() {
  if ((this.minWidth != '' && this.width > this.minWidth) || (this.minHeight != '' && this.height < this.minHeight)) {
    alert('您所上传的图片尺寸太小了!/n上传的图片大小至少要 ' + this.minWidth + ' x ' + this.minHeight); return;}
  if ((this.maxWidth != '' && this.width > this.maxWidth) || (this.maxHeight != '' && this.height > this.maxHeight)) {
    alert('您所上传的图片尺寸为 '+ this.width + ' x ' + this.height+' 太大了!/n上传的图片大小不可超过 ' + this.maxWidth + ' x ' + this.maxHeight); return;}
  if (this.sizeLimit != '' && this.fileSize/1000 > this.sizeLimit) {
    alert('您所上传的档案为 '+this.fileSize/1000+' KB太大了!/n最大不可超过 ' + this.sizeLimit + ' KB'); return;}
  if (this.saveWidth != '') document.PU_uploadForm[this.saveWidth].value = this.width;
  if (this.saveHeight != '') document.PU_uploadForm[this.saveHeight].value = this.height;
  document.MM_returnValue = true;
}

function checkImageDimensions(fileName,sizeLimit,minWidth,minHeight,maxWidth,maxHeight,saveWidth,saveHeight) { //v2.0
  document.MM_returnValue = false; var imgURL = 'file:///' + fileName, img = new Image();
  img.sizeLimit = sizeLimit; img.minWidth = minWidth; img.minHeight = minHeight; img.maxWidth = maxWidth; img.maxHeight = maxHeight;
  img.saveWidth = saveWidth; img.saveHeight = saveHeight;
  img.onload = showImageDimensions; img.src = imgURL;
}
//-->
</script>
<style type="text/css">
<!--
form {
 margin: 0px;
}
.formword {
 font-family: "Georgia", "Times New Roman", "Times", "serif";
 font-size: 8pt;
}
-->
</style>
<style type="text/css">
<!--
.box {
 border: 1px dotted #333333;
}
-->
</style>
</head>
<body bgcolor="#EEEEEE" text="#333333" leftmargin="2" topmargin="2" marginwidth="2" marginheight="2">
<script language="JavaScript" type="text/JavaScript">
var windowW = 400;
var windowH = 180;
windowX = Math.ceil( (window.screen.width  - windowW) / 2 );
windowY = Math.ceil( (window.screen.height - windowH) / 2 );
window.resizeTo( Math.ceil( windowW ) , Math.ceil( windowH ) );
window.moveTo( Math.ceil( windowX ) , Math.ceil( windowY ) );
</script>
<form ACTION="fupaction.asp" METHOD="POST" name="form1" enctype="multipart/form-data" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,PNG',true,'<%If Request("imgS") <> "" then Response.Write(Request("imgS"))%>','','','<%if Request("imgW")<>"" then Response.Write(Request("imgW"))%>','<%if Request("imgH") <> "" Then Response.Write(Request("imgH"))%>','','');return document.MM_returnValue">
  <table width="100%" height="100%" border="0" cellpadding="4" cellspacing="0">
    <tr>
      <td height="20"><table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#999999">
          <tr valign="baseline" class="formword">
            <td width="40" align="right"><font color="#FFFFFF">注意:</font></td>
            <td><font color="#FFFFFF"> 请选取图片上传,允许类型为GIF、JPG、JPEG、PNG
   <%if Request("imgS") <>"" then%>
   ,档案大小不可超过 <%= Request("ImgS") %> KB
   <%end if%>
   。</font></td>
          </tr>
        </table>
       
      </td>
    </tr>
    <tr>
      <td height="20" align="center">
        <table border="0" cellpadding="4" cellspacing="0">
          <tr>
            <td><input name="upfile" type="file" class="formword" id="upfile" size="40"></td>
          </tr>
        </table>
        <input name="Submit" type="submit" class="formword" value="开始上传"> <input name="close" type="button" class="formword" onClick="window.close();" value="关闭视窗">
        <input name="useForm" type="hidden" id="useForm" value="<%=Request("useForm")%>">
        <input name="upUrl" type="hidden" id="upUrl" value="<%=Request("upUrl")%>">
        <input name="prevImg" type="hidden" id="prevImg" value="<%=Request("prevImg")%>">
        <input name="reItem" type="hidden" id="reItem" value="<%=Request("reItem")%>">
      </td>
    </tr>
    <tr>
      <td height="20" align="center">
        <table width="100%" border="0" cellpadding="4" cellspacing="0" bgcolor="#FFFFFF" class="box">
          <tr valign="baseline" class="formword">
            <td align="center"> Copyright &copy; 2003 <a href="http://www.e-dreamer.idv.tw" target="_blank">eDreamer</a>
              Inc. All rights reserved.</td>
          </tr>
        </table> </td>
    </tr>
  </table>
  </form>
</body>
</html>
 

原创粉丝点击