Solved

Converting PHP Code to Coldfusion

Posted on 2013-11-01
3
947 Views
Last Modified: 2013-11-01
I'm trying to implement a proxy for html2canvas (http://html2canvas.hertzen.com/) in Coldfusion.

I've found a script created in PHP but I have no experience and not much time to replicate the code in CF.

I did the following as of now in CF

What I'm not sure is the code (PHP file) in line 22

    $re_encoded_image = sprintf(
            'data:%s;base64,%s', $file_details["mime_type"], base64_encode($file_details["data"])
    );

    print "{$callback}(" . json_encode($re_encoded_image) . ")";

Open in new window


I know that SerializeJSON = json_encode in PHP

<cfhttp url="#url.url#"    
	timeout="45"
    throwonerror="true"
    method="get"
	result="resp">
</cfhttp>
<cfset img = resp.fileContent />
<cfcontent type="application/javascript" />
<cfoutput>#url.callback#("#SerializeJSON(img)#");</cfoutput>

Open in new window



Link to PHP file (https://github.com/adjdred/html2canvas-proxy-php/blob/master/proxy.php)

I've also attached the php file.
0
Comment
Question by:ymorin007
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39617856
I'm not real familiar with php, but looks like that part just returns a string with a base64 encoded image and mime type.

           data:some_mime_type_here;base64,base_64_encoded_image_here

If your cfhttp call returns a binary image, just grab the mime type and convert the fileContent to base64. Not tested, but something along these lines ...

     <!--- check for errors first obviously ...--->
     <cfset str = "data:"& resp.mimeType &";base64,"& binaryEncode(resp.fileContent, "base64")>

Then run it through SerializeJSON. But don't forget the brackets {} and parenthesis when you create the final string. The output should look something like this
 
     { your_callback_name_here }( your_json_string_here );
0
 

Author Comment

by:ymorin007
ID: 39617906
Thanks a million you are my lifesaver ... It work perfectly.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39617910
Great, glad I could help!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now