WordPress.org

Ready to get started?Download WordPress

Forums

Flickr Shortcode Importer by Aihrus
[resolved] [Plugin: Flickr Shortcode Importer] file_get_contents with url ISP does not support (3 posts)

  1. tobylewis
    Member
    Posted 2 years ago #

    Hi

    My isp does not allow file_get_contents to use urls, only local files. I replaced the call with a curl equivalent function (shown below). But then I got

    {"error":""About" Post ID 24 failed to be processed. The error message was: Unknown failure reason."}

    I'm using WordPress 3.3.2. PHP Version 5.2.17.

    I'll try and figure out what is going on but using curl might be a good addition for the next update anyway.

    ~Toby

    function file_get_contents_curl($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
    }

    http://wordpress.org/extend/plugins/flickr-shortcode-importer/

  2. tobylewis
    Member
    Posted 2 years ago #

    The error was due to there being no titles on the files on flickr. prevent problem by checking $title has a value before using it.

    if ($title && fsi_get_options( 'replace_file_name' ) ) {

    also here is a more robust curl function

    function file_get_contents_curl($url) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
    }

  3. Michael Cannon
    Member
    Plugin Author

    Posted 2 years ago #

    Great suggestion. Only problem will be when curl isn't compiled into PHP.

    Anyways, I've put the code in for upcoming 1.7.8. We'll see what happens.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic