-4

I am having problems enabling file_get_contents on my site. It was suggested I could use curl instead.

This is my original function, using file_get_contents:

function getFile($fileQuery){
  global $user, $pass, $domain;

  return file_get_contents("https://$user:$pass@$domain:2083/".$fileQuery);

}

And this is what I tried, using curl:

function getFile($fileQuery){
  global $user, $pass, $domain;

  //return file_get_contents("https://$user:$pass@$domain:2083/".$fileQuery);

  $url = "https://$user:$pass@$domain:2083/".$fileQuery;
    $ch = curl_init();    
    curl_setopt($ch, CURLOPT_URL,$url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable  

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 4000);    //timeout in seconds

    $result = curl_exec($ch);  
    echo "<pre>"; print_r($result);  
    curl_close($ch); 


}

However, it's returning a blank page.

Any ideas?

legoscia
  • 39,593
  • 22
  • 116
  • 167
Satch3000
  • 47,356
  • 86
  • 216
  • 346

1 Answers1

2

You can use curl instead of file_get_contents in the following way:

   $url = "https://$user:$pass@$domain:2083/".$fileQuery;
    $ch = curl_init();    
    curl_setopt($ch, CURLOPT_URL,$url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable  

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 4000);    //timeout in seconds

    $result = curl_exec($ch);  
    echo "<pre>"; print_r($result);  
    curl_close($ch);  
Dinesh Nagar
  • 768
  • 2
  • 11
  • 23
  • Thanks for your reply. I'm updated my question...please see main question. Tried adding this code to the function but getting a blank page. – Satch3000 Jul 31 '14 at 14:12
  • Can you please provide me full url https://$user:$pass@$domain:2083/".$fileQuery i mean what the value of $fileQuery here so that i can test and fix your problem. – Dinesh Nagar Jul 31 '14 at 14:14
  • Sorry, I'm not allowed to give the site url here. I understand if you can no longer help me because of that. – Satch3000 Jul 31 '14 at 14:17
  • 2
    Step 1. if(curl_errno($ch)){ echo 'Curl error: ' . curl_error($ch); } use this block of code this will print exactly what the error is or Step 2. you can give a dummy url of a any webpage which returns data if it returns that means there is a problem in your url. – Dinesh Nagar Jul 31 '14 at 14:19