0

I'm wondering what would make this code falsely fail. It returns false result when passing certain Image URLs. I don't have control of what the URL is, but I can encode it somehow to make this work?

I assume the problem lays with the space located in the Image URL. How to avoid this?

function checkRemoteFile($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    // don't download content
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    return (curl_exec($ch)!==FALSE);
}
Davide
  • 1,635
  • 1
  • 16
  • 29
HelpNeeder
  • 6,383
  • 24
  • 91
  • 155

1 Answers1

1

Use $url = str_replace(' ','%20',$url); to urlencode the spaces.

hellcode
  • 2,678
  • 1
  • 17
  • 21
  • I just found it right before I seen your answer. But thanks. http://stackoverflow.com/questions/5931853/curl-requesting-url-with-whitespaces-in-url-what-to-do – HelpNeeder Oct 08 '14 at 19:24