<!--#include virtual="/NR/System/WBC/Internals/Main/WBCApp.inc"--><%
  response.flush

  if AutoSession.Session.SettingCanEditSession = false then
	response.End
  end if

  if AutoSession.UserCanAuthor = false then
	response.End
  end if

  dim pMyPlaceholder
  set pMyPlaceholder = AutoSession.This.Placeholders( CStr(Request.QueryString("ph")) )

  Dim strBaseFilename
  strBaseFilename = Request.QueryString("filename")

  Dim bImageTag
  bImageTag = false

  if pMyPlaceholder.XAllowsImageUpload then
	if (StrComp(Right(strBaseFilename, 4),".gif",1) = 0) OR _
	   (StrComp(Right(strBaseFilename, 4),".jpg",1) = 0) OR _
	   (StrComp(Right(strBaseFilename, 5),".jpeg",1) = 0) then

		bImageTag = true
	end if
  elseif pMyPlaceholder.XAllowsAttachmentUpload then
    bImageTag = false
  else
    Response.End
  end if

  dim BinFile
  Set BinFile = Server.CreateObject("AEBinFile.AEBinFile.1")

  Dim regEx
  Set regEx = New RegExp         ' Create regular expression.
  regEx.Pattern = "[^a-zA-Z0-9.]"
  regEx.Global = true
  
  strBaseFilename = regEx.Replace(strBaseFilename, "_")

  dim strFilename
  strFilename = BinFile.CreateTemporaryFile( CLng(Request.ServerVariables("INSTANCE_ID")) , strBaseFilename, "")

  dim nCount, VariantBytes
  Do
	nCount = 100000
	VariantBytes = Request.BinaryRead(nCount)

	If (nCount > 0)Then
		Call BinFile.Write(VariantBytes, nCount)
	End If
   Loop While (nCount <> 0)

   Call BinFile.CloseFile()

   on error resume next
   Dim strUrl
   strUrl = AutoSession.AcceptBinaryFile(strFilename)

   if err.number <> 0 then
	Response.End
   end if

   call BinFile.DeleteTemporaryFile

   if bImageTag then
		Response.Write "<IMG BORDER=0 SRC='" & strUrl & "'>"
   else
		Response.Write "<A HREF='" & strUrl & "'><IMG BORDER=0 SRC='" & strUrl & "?thumbnail=true&label=" & Server.URLEncode(strBaseFilename) & "'></A>"
   end if
%>