[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 466
  • Last Modified:

translatation of php to asp

I have a small php-script that receives some xml-formatted text from a flash-movie and create a xml-file on the server. See the code-snippet.
Can anyone tanslate that into asp or ASP.NET.
<?php 
if (isset($GLOBALS["HTTP_RAW_POST_DATA"])){ 
//    $xml = xmldoc($GLOBALS["HTTP_RAW_POST_DATA"]); 
    $xml = $GLOBALS["HTTP_RAW_POST_DATA"]; 
    $file = fopen("data.xml","wb"); 
    fwrite($file, $xml); 
    fclose($file); 
//    echo("<status>File saved.</status>"); 
    echo($GLOBALS["HTTP_RAW_POST_DATA"]); 
} 
?>

Open in new window

0
petersego
Asked:
petersego
  • 2
  • 2
1 Solution
 
iandianCommented:
This might work.

reused the RSBinaryToString function found somewhere else, so i won't take credit for that.

This code removes all data from the xml file before writing. change the settign from 2 to 8 in the openTextFile function to append

This code is not testen, but i think it should work.
<%Function RSBinaryToString(xBinary)
  Dim Binary
  If vartype(xBinary)=8 Then Binary = MultiByteToBinary(xBinary) Else Binary = xBinary

  Dim RS, LBinary
  Const adLongVarChar = 201
  Set RS = CreateObject("ADODB.Recordset")
  LBinary = LenB(Binary)

  If LBinary>0 Then
    RS.Fields.Append "mBinary", adLongVarChar, LBinary
    RS.Open
    RS.AddNew
      RS("mBinary").AppendChunk Binary
    RS.Update
    RSBinaryToString = RS("mBinary")
  Else
    RSBinaryToString = ""
  End If
End Function

Dim ByteCount, BinRead, textString, fs, f
ByteCount = Request.TotalBytes
If ByteCount > 0 Then
BinRead = Request.BinaryRead(ByteCount)
textString = RSBinaryToString(BinRead))
set fs = Server.CreateObject("Scripting.FileSystemObject")
set f = fs.OpenTextFile("data.xml", 2, true)
f.write(textString)
f.close()
set f=nothing
set fs=nothing
response.write(textString)
end if
%>

Open in new window

0
 
petersegoAuthor Commented:
Thanks, it looks convincing, but it does not work. I don't know why.
Ive made sure that the permissions are set to writeable (777).
Im not sure what the binary function is there for - is that the right approach.
I assume that it's where you get the POST from flash.
0
 
petersegoAuthor Commented:
In the meantime, I found this script, I got to work succesfully.
http://www.hosfordusa.com/?p000100000191000000


<%@ language = "JScript" %>
<%

/*----------------------------------------------------------------------
	Copyright:			2005 Lon Hosford: http://www.lonhosford.com
						Permission to use in your own applications
						but not to use for publication electronically
						or otherwise without written permission.
						Links to this page are welcomed.

	Purpose:			Simple example Flash XML to ASP and Back
						with writing XML to text file on server.

	Comments:			Requires that the server allow create
						and write permissions in the folder containing
						this script.

						Tested on IIS5.1 server running under Windows XP


	Version history:
		Number:			1.00.00
		Date:			12/27/2005
		File name:		XMLASPEchoEx01_Response.asp
		Programmer:		Lon Hosford: http://www.lonhosford.com
		Changes:		Original programming
------------------------------------------------------------------------
 	Define response data as xml
---------------------------------------------------------------------*/
Response.ContentType = "text/xml";
/*----------------------------------------------------------------------
	Create XMLDOM object for handling the XML data received
---------------------------------------------------------------------*/
var xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
/*----------------------------------------------------------------------
	Force the XMLDOM object load method to complete before proceeding
	to next line in script
---------------------------------------------------------------------*/
xmlDoc.async = false;
/*----------------------------------------------------------------------
	Load the ASP Request object as the source for the XMLDOM object
---------------------------------------------------------------------*/
xmlDoc.load(Request);
/*----------------------------------------------------------------------
	Constants used in Scripting.FileSystemObject
---------------------------------------------------------------------*/
var FOR_WRITING = 2;
var TRIASCII = 0;
var OVERWRITE = true;
/*----------------------------------------------------------------------
	Create Scripting.FileSystemObject
---------------------------------------------------------------------*/
var oFS = Server.CreateObject("Scripting.FileSystemObject");
/*----------------------------------------------------------------------
	Create a Test.xml file in same folder as this script
---------------------------------------------------------------------*/
oFS.createTextFile(Server.MapPath("Test.xml"), OVERWRITE);
/*----------------------------------------------------------------------
	Open a Test.xml file for writing with ASCII
---------------------------------------------------------------------*/
var oFSFile = oFS.openTextFile(Server.MapPath("Test.xml") ,FOR_WRITING,TRIASCII);
/*----------------------------------------------------------------------
	Write the xml from Flash as a string to Test.xml file
---------------------------------------------------------------------*/
 oFSFile.write(xmlDoc.xml);
/*----------------------------------------------------------------------
	Close the Test.xml file
---------------------------------------------------------------------*/
 oFSFile.close();
/*----------------------------------------------------------------------
	Return the received XML from Flash back to Flash with an
	additional wrapper XML node
---------------------------------------------------------------------*/
Response.write("<dataPacket>"+ xmlDoc.xml + "</dataPacket>");
/*----------------------------------------------------------------------
	Force all data responses back
---------------------------------------------------------------------*/
Response.flush();
/*----------------------------------------------------------------------
	Terminate any further responses
---------------------------------------------------------------------*/
Response.end();
%>

Open in new window

0
 
iandianCommented:
Hmm, i don't knwo why but i missed the XML from flash part completely...

Thanks for posting the solution you found, might be helpfull for others. Maybe you can award yourself some points :)
0
 
ee_autoCommented:
Question PAQ'd, 500 points refunded, and stored in the solution database.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now