Hi! evryone!
My cody is run nice but the uploaded png is black and size is only 3bytes.
I want to know what difference between webpage form and wwwform when uploadfile! Thanks!
screen.js
var screenShotURL= "http://*.*.*.*/screenshot.asp";
// Take a screen shot immediately
function Start()
{
print("uping...");
UploadPNG();
}
function UploadPNG()
{
// We should only read the screen after all rendering is complete
yield WaitForEndOfFrame();
var width = Screen.width;
var height = Screen.height;
(Screen.width, Screen.height, 24);
// Create a texture the size of the screen, RGB24 format
var tex = new Texture2D( width, height, TextureFormat.RGB24, false );
// Read screen contents into the texture
tex.ReadPixels( Rect(0, 0, width, height), 0, 0 );
tex.Apply();
// Encode texture into PNG
var bytes = tex.EncodeToPNG();
Destroy( tex );
//File.WriteAllBytes(Application.dataPath + "/../Temp/SavedScreen.png", bytes);
// Create a Web Form
var form = new WWWForm();
//form.AddField("filepath", "screenshot_img");
form.AddBinaryData("fileUpload", bytes, "screenShot.png", "image/png");
// Upload to a cgi script
var w = WWW(screenShotURL, form);
yield w;
if (w.error != null)
{
print(w.error);
}
else
{
print(w.data);
}
}
screenshot.asp
<%
dim filePath:filePath=server.MapPath("/")"\screenshot_img/" ' save path
dim lf:lf=chrB(13)&chrB(10)
dim hct:hct=request.ServerVariables("CONTENT_TYPE") ' the file type
'response.write "request.ServerVariables("CONTENT_TYPE"): "
'response.write hct
dim bTotal ' bytes size
bTotal=cLng(request.TotalBytes)
'response.write bTotal
dim bRead
bRead=request.BinaryRead(bTotal)
dim bStart:bStart=instrB(bRead,lf&lf)+3 ' start pos
'response.Write bStart
dim cTy:cTy=binToStr(midB(bRead,1,bStart-1)) ' Field head info
'response.Write cTy
dim fieldMarker ' Field marker
fieldMarker=leftB(bRead,inStrB(bRead,chrB(13))-1)
dim cDesc ' Field desc info
cDesc=fRegExpSgl(cTy,true,true,true,"[\s\S]*?Content-Disposition\: (.*?)\;[\s\S]*","$1")
dim fldName ' Field name
fldName=fRegExpSgl(cTy,true,true,true,"[\s\S]*?name\=\""(.*?)""[\s\S]*","$1")
'response.Write fldName
dim fileName
fileName=fRegExpSgl(cTy,true,true,true,"[\s\S]*filename\=""(.*?)""[\s\S]*","$1")
'response.Write fileName
dim cTp 'MIME type desc
cTp=fRegExpSgl(cTy,true,true,true,"[\s\S]*?Content-Type\:(.*?)","$1")
'response.Write cTp
dim bEnd ' end pos
bEnd=inStrB(bStart+6,bRead,fieldMarker)-bStart-3
''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim stm
set stm=createObject("adodb.stream")
stm.type=1
stm.mode=3 ' read and write mode
stm.open
stm.write bRead
dim fromStm
set fromStm=createOBject("adodb.stream")
with fromStm
.type=1
.mode=3
.open
stm.position = bStart
stm.copyTo fromStm, bEnd
.saveTofile filePath&fileName,2 ' save file overwrite mode
.close
end with
set fromStm=nothing
stm.close
set stm=nothing
response.Write("update ok")
''''''''''''''''''''''
''''''''''''''''''''''
function fRegExpSgl(str,glb,igc,mtl,pt,rpt)
dim re
set re=new RegExp
re.global=glb
re.ignoreCase=igc
re.multiline=mtl
re.pattern=pt
fRegExpSgl=re.replace(str,rpt)
set re=nothing
end function
private function binToStr(bin) 'bytes to string (bmp|gif|png|jpg)
dim i, iByt, sByt, bLen:bLen=lenB(bin)
for i=1 to bLen
sByt=midB(bin,i,1):iByt=ascB(sByt)
if iByt<128 then
binToStr=binToStr&chr(iByt)
else:i=i+1
if i<=bLen then binToStr=binToStr&chr(ascW(sByt&sByt))
end if
next
end function
%>
Does anyone have some ASP VBScript code that upload a PNG from unity and saves it on their server?