ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Problem using file_get_contents in PHP

December 22, 2010 12:46pm

Subscribe [2]
  • #1 / Dec 22, 2010 12:46pm

    Adam Engst

    12 posts

    I’m trying to embed a PDF document viewer on my site, and to do so in a secure fashion entails retrieving the data from a remote site. To do that, the sample code provided by the PDF viewer company uses file_get_contents. However, whenever I have the file_get_contents statement, with any URL, my page simply doesn’t load at all. I do have PHP on (it’s used to generate the entire page this is on, successfully in every other way), and set to Output, and as far as I can tell, fopen() wrappers are turned on. Initially, I’d thought the problem might be related to the URL not being URL-encoded, but when I URL encode it, the file_get_contents command does nothing (which enables the page to load, but without retrieving the necessary data).

    Any ideas why file_get_open is failing? Thanks!

    cheers… -Adam

    PS: Here’s the code snippet:

    {!-- This code encrypts all the data in the transaction so the URL is not visible.  --}
    $cloudconnectkey = "foobar";
    $documentLocation = "https://www.takecontrolbooks.com/pdf/" . $read_online;
    $urlstring = "http://connect.ajaxdocumentviewer.com/encrypt/?key=" . $cloudconnectkey . "&document;=" . $documentLocation . "&viewerheight=1050&viewerwidth=900&cache=No&printButton=No&saveButton=No&logoimage=http://www.takecontrolbooks.com/tc-graphics/tc_web_title_ebooks_v02.gif&quality=high&ssl=No";
    {!-- If the line below is enabled, the page tries to load until it times out. If I use any URL in place of $urlstring, the page will not load; if I use any non-URL, the page loads but $encryptedStr is blank. --}
    $encryptedStr = file_get_contents($urlstring);
    $embedLink = "http://connect.ajaxdocumentviewer.com/?key=" . $cloudconnectkey . "&encrypt=1&encrypttext;=" . $encryptedStr;
    $cloud_connect_display_ssl = "<a href="http://">{title}</a>";
    
    echo $cloud_connect_display_ssl . "
    ";
    {!-- The line below shows that urlstring is being generated correctly. --}
    echo "<strong>urlstring</strong>: " . $urlstring . "
    ";
    {!-- The line below shows that when $encryptedStr is generated via file_get_open pointing at a non-URL, $encryptedStr remains blank. --}
    echo "<strong>encryptedStr</strong>: " . $encryptedStr . "
    ";
    {!-- The line below shows that $embedLink is generated correctly, short of $encryptedStr. --}
    echo "<strong>embedLink</strong>: " . $embedLink . "
    ";
    {!-- Tried the line below as a test; if it's enabled, the page won't load either. --}
    {!-- echo "<strong>Test</strong>: " . file_get_contents ('http://www.tidbits.com/')  . "
    "; --}
  • #2 / Dec 22, 2010 11:21pm

    Brandon Jones

    5500 posts

    Hi Adam,

    Which version and build of EE are you using?

    This might be better implemented as an add-on, and we may need to move this over to the CodeShare Corner, but when you say the page “doesn’t load at all” does that mean you’re getting a blank page? Have you tried enabling error reporting to debug further?

  • #3 / Dec 30, 2010 2:48pm

    Adam Engst

    12 posts

    Hi Brandon,

    I’m using EE 1.7.0.

    When I say that the page doesn’t load, I mean that the browser simply says “Contacting server…” in the status line until something times out. No page loads at all, blank or otherwise.

    I have not tried enabling error reporting, but I’ll see about that…

    cheers… -Adam

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases