Solved

Converting PHP Code to Coldfusion

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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