<%@ LANGUAGE = "VBScript.Encode" codepage="65001" %>
 <!--#include FILE="../inc/conn.asp"-->
 <!--#include FILE="../inc/inc.asp"-->
<%
Server.ScriptTimeOut=999999
%>
<html>
<head>
<title>上传反馈信息</title>
</head>

<body bgcolor="#666666">
<table width="100%" border="0" height="100%">
  <tr>
    <td>
      <table width="80%" height="200" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#000000">
        <tr> 
          <td valign="middle"> <table width="99%" border="0" align="center" bgcolor="#FFFFFF" height="99%" cellpadding="20">
              <tr> 
                <td> 
 <!--#include FILE="upload_5xsoft.inc"-->
 <%

Function CreateOnlyID()
	tmpid=right(year(now()),2)
	tmpid=tmpid & month(now())
	tmpid=tmpid & day(now())
	tmpid=tmpid & hour(now())
	tmpid=tmpid & minute(now())
	tmpid=tmpid & second(now())
	Randomize
	upperbound=99999
	lowerbound=10000
	tmpid=tmpid & Int((upperbound - lowerbound + 1) * Rnd + lowerbound) 
	CreateOnlyID=tmpid
End Function
function TrueStr(fileTrue)
 str_len=len(fileTrue)
 pos=Instr(fileTrue,chr(0))
 if pos=0 or pos=str_len then
 	TrueStr=true
 else
 	TrueStr=false
 end if
end function

'******************************************************************
'CheckFileType 函数用来检查文件是否为图片文件
'参数filename是本地文件的路径
'如果是文件jpeg,gif,bmp,png图片中的一种，函数返回true，否则返回false
'******************************************************************
const adTypeBinary=1
dim jpg(1):jpg(0)=CByte(&HFF):jpg(1)=CByte(&HD8)
dim bmp(1):bmp(0)=CByte(&H42):bmp(1)=CByte(&H4D)
dim png(3):png(0)=CByte(&H89):png(1)=CByte(&H50):png(2)=CByte(&H4E):png(3)=CByte(&H47)
dim gif(5):gif(0)=CByte(&H47):gif(1)=CByte(&H49):gif(2)=CByte(&H46):gif(3)=CByte(&H39):gif(4)=CByte(&H38):gif(5)=CByte(&H61)

function CheckFileType(filename)
	on error resume next
	CheckFileType=false
	dim fstream,fileExt,stamp,i
	fileExt=mid(filename,InStrRev(filename,".")+1)
	set fstream=Server.createobject("ADODB.Stream")
	fstream.Open
	fstream.Type=adTypeBinary
	fstream.LoadFromFile filename
	fstream.position=0
	select case fileExt
		case "jpg","jpeg"
			stamp=fstream.read(2)
			for i=0 to 1
				if ascB(MidB(stamp,i+1,1))=jpg(i) then CheckFileType=true else CheckFileType=false
			next
		case "gif"
			stamp=fstream.read(6)
			for i=0 to 5
				if ascB(MidB(stamp,i+1,1))=gif(i) then CheckFileType=true else CheckFileType=false
			next
		case "png"
			stamp=fstream.read(4)
			for i=0 to 3
				if ascB(MidB(stamp,i+1,1))=png(i) then CheckFileType=true else CheckFileType=false
			next
		case "bmp"
			stamp=fstream.read(2)
			for i=0 to 1
				if ascB(MidB(stamp,i+1,1))=bmp(i) then CheckFileType=true else CheckFileType=false
			next
		end select
	fstream.Close
	set fseteam=nothing
	if err.number<>0 then CheckFileType=false
end function
set upload=new upload_5xsoft
set file=upload.file("file1")
if session("uppath")="" then uppath="other"
	uppath=session("uppath")
	ProdId=session("ProdId")
	frmname=session("frmname")
if uppath="" then 
	response.write "<BLOCKQUOTE>参数错误！请返回前一个页面<b>刷新后</b>上传！"
	Response.write "<br><A HREF='javascript:history.go(-1)'><b>点击返回,然后刷新页面</b></A></BLOCKQUOTE>"
	response.end
end if
if file.fileSize>0 then
    '自动生成文件名
    Tfilename=date()
    Tfilename=Tfilename&time()
    Tfilename=replace(Tfilename,"-","")
    Tfilename=replace(Tfilename,":","")
    Tfilename=replace(Tfilename," ","")
    Tfilename=createonlyid()&"."
    Tfilenameend=file.filename
    Tfilenameend=split(Tfilenameend,".")
    Tfilename=Tfilename&Tfilenameend(1)
	if Tfilenameend(1)="gif" or Tfilenameend(1)="jpg" or Tfilenameend(1)="GIF" or Tfilenameend(1)="JPG" then
	else
	response.write "<BLOCKQUOTE>请确认上传的图片类型为 jpg 或者 gif 或者swf"
		Response.write "<br><br>操作失败！<A HREF='javascript:history.go(-1)'><b>点击返回</b></A></BLOCKQUOTE>"
		response.end
	end if
	web_tpath=Web_Get_RootDir(Web_C_setupfolder)&"uploadimage/"&uppath&""
	    if TrueStr(web_tpath)=false then
        	  response.write "<script>alert('非法文件');window.close()</script>"
       		  response.end
    	    end if
	file.saveAs Server.mappath("../uploadimage/"&uppath&"/"&Tfilename) 
	web_filepath=Server.mappath("../uploadimage/"&uppath&"/"&Tfilename)
	
            If not CheckFileType(lcase(web_filepath)) then
            	Set fso = CreateObject(C_Web_FSO)
            	Set ficn = fso.GetFile(web_filepath)
           	ficn.delete
           	set ficn=nothing
            	set fso=nothing
		 response.write "<script>alert('非法图片格式');window.close()</script>"
            	response.end
            end if
    	
%>
<%if session("prodid")="one" then%>
<script language=JavaScript>
function inserttext(){
<%
	response.write "self.opener.myform."&frmname&".value =""uploadimage/"&uppath&"/"&tfilename&""";"
%>
}
inserttext();
alert("文件上传成功");
window.close();
</script>
<% else %>
<%
  response.write "<br><center><font size=2 color=red>图片上传成功，请复制下边剪切板中内容而后粘贴到商品图片剪切板内!</font></center><br>"
  response.write "<center><input type=text size=26 value='images/"&uppath&"/"&filename&"'><button onclick=window.clipboardData.setData('text',this.previousSibling.value)>复制</button><br><br><a href='javascript:window.close()'><font color=red size=2>关闭窗口</font></a></center>"
  response.end
%>
<% end if%>
<%

else
    response.write "文件内容不能为空"
    response.write "<a href='javascript:history.go(-1);'>返回"
end if
set upload=nothing
response.write "<br>"
%>
                </td>
              </tr>

            </table></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body> 
</html>
<%
session("uppath")=""
session("ProdId")=""
session("frmname")=""
%> 
