Solved

Converting PHP Code to Coldfusion

Posted on 2013-11-01
3
951 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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…

914 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

21 Experts available now in Live!

Get 1:1 Help Now