PHP to ASP help - Posted (2096 Views)
Junior Member
phoenixtaz13
Posts: 129
129
Hi guys... good day to you all...
for days i've been trying to figure out how to implement the PHP codes to ASP codes.
in HTML file
Code:
function saveImage(){
var data = myCanvas.toDataURL();
var request = new XMLHttpRequest();
request.open('POST', 'save.php', true);
request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
request.send('img='+data);


}


and the html calls on this save.php file
Code:
define('UPLOAD_DIR', 'images/');
$img = $_POST['img'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = UPLOAD_DIR . uniqid() . '.png';
$success = file_put_contents($file, $data);
print $success ? $file : 'Unable to save the file.';

is it possible for the save.php file implemented in ASP codes? if yes, what should i be looking into to make it work? can you guys show me some examples to implement it....
thanks...
 Sort direction, for dates DESC means newest first  
 Page size 
Posted
Forum Admin
HuwR
Posts: 20611
20611
I'm assuming you mean cross domain posting is the issue here.
try adding the option crossDomain: true, to the $ajax post options
Posted
Junior Member
phoenixtaz13
Posts: 129
129
Hi Huwr.. :) tried crossDomain: 'true',

in default.asp file

Code:
<head>
<title>HTML5 Canvas JavaScript Ajax Cross Domain</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>

<script type="text/javascript">

function btnSaveImage() {

// generate the image data
var Pic = document.getElementById("myCanvas").toDataURL("image/png");
Pic = Pic.replace(/^data:image\/(png|jpg);base64,/, "")

// Sending the image data to Server
$.ajax({
type: 'POST',
crossDomain: 'true',
url: 'crossdomain.asp',
data: '{ "imageData" : "' + Pic + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("Done, Picture Uploaded.");
}
});


}

</script>
</head>


in crossdomain.asp file
Code:

<%@ Language=VBScript %>
<%


Dim strImageURL

Dim strImageURL
strImageURL = request("imageData")
'response.write(request("imageData"))
response.write(strImageURL)

response.write "<script>window.open('"& strImageURL &"', '_blank', 'location=0, menubar=0');</script>"
response.write (<script>alert('triggered')</script>)


' Function Base64Data2Stream(sData)
' Set Base64Data2Stream = Server.CreateObject("Adodb.Stream")
' Base64Data2Stream.Type = 1 'adTypeBinary
' Base64Data2Stream.Open
' With Server.CreateObject("MSXML2.DomDocument.6.0").createElement("b64")
' .dataType = "bin.base64"
' .text = sData
' Base64Data2Stream.Write .nodeTypedValue 'write bytes of decoded base64 to stream
' Base64Data2Stream.Position = 0
' End With
' End Function
'
' Dim CanvasStream
' Set CanvasStream = Base64Data2Stream(strImageURL)

' Write binary to Response Stream
' Response.BinaryWrite CanvasStream.Read

' Write binary to File
' CanvasStream.SaveToFile Server.Mappath("images/" & "picSave".png), 2 'adSaveCreateOverWrite



%>

i'm using google chrome, even in simple code window.open or alert to display the data wont work either... :(

the error im getting in google chrome:
Code:

POST http://aspwebtest/crossdomain/crossdomain.asp 500 (Internal Server Error)     jquery.min.js:4

f.support.ajax.f.ajaxTransport.send @ jquery.min.js:4
f.extend.ajax @ jquery.min.js:4
btnSaveImage @ (index):18
onclick @ (index):91


all files are in http://aspwebtest/crossdomain/
What am i missing?... did i do it right?.... help... help... help pls....







You Must enter a message