?
Solved

Converting PHP Code to Coldfusion

Posted on 2013-11-01
3
Medium Priority
?
1,000 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 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

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

771 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