Warning: Failed to open stream .... why?

Discussion in 'PHP' started by BRUm, Aug 25, 2006.

  1. #1
    Hi,

    I need to file_get_contents of multiple website dynamically, so I use arrays in a loop to connect to. Here's a snippet:

    
    for ($i = 1; $i < sizeof($linkarray[0])-3; $i++){
        echo ("<a href=" . $linkarray[1][$i] . "> <font color='red'><b>" . $linkarray[2][$i] . "</b></a></font><br><br> ");
        $ccontent = file_get_contents($linkarray[1][$i]);
    $rele = preg_match("/".$pieces[0].".*/", $ccontent, $rel);
    ECHO $rel[0]."<BR><BR>";
    }
    PHP:

    So it loops, and gets the contents of some sites, yet when I echo the output array $rel[0]; I get Failed to stream for each one, despite them being valid URLs.

    If someone could help it would be great ,

    Thanks,

    Lee.
     
    BRUm, Aug 25, 2006 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    Anyone? :/
     
    BRUm, Aug 26, 2006 IP
  3. gigapromoters

    gigapromoters Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am not sure, can you show me the code where $linkarray was initialized..
     
    gigapromoters, Aug 26, 2006 IP
  4. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #4
    $linkarray is just a simple array with data. $linkarray[1][$x] contains all the URLs. I get errors like:

    Warning: file_get_contents("http://www.autotrader.co.uk/"): failed to open stream: No such file or directory in /home/hydropow/public_html/izearch/searched.php on line 173
    Code (markup):
    Anyone help?
     
    BRUm, Aug 26, 2006 IP
  5. Litewebsite

    Litewebsite Guest

    Messages:
    26
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It sounds like the allow_url_fopen is disabled, which means remote pages can't be fetched. You can change this in the php.ini file or with ini_set('allow_url_fopen', 1); in your script

    More info at php.net: php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen
     
    Litewebsite, Aug 26, 2006 IP
  6. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #6
    Hm, Just tried it, it didn't work :(

    I think it may be the array.. does anyone know the most simple way to turn an array into a string?

    Thanks,

    Lee.
     
    BRUm, Aug 26, 2006 IP
  7. Litewebsite

    Litewebsite Guest

    Messages:
    26
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Did you try with the php.ini or ini_set()? According to the php.net changelog ini_set() only works with "PHP_INI_ALL in PHP <= 4.3.4".

    You can check allow_url_fopen with

    
    <?php
    echo ini_get('allow_url_fopen');
    // or this function
    echo phpinfo(); // look under "PHP core"
    ?>
    
    PHP:
    Hope this can help you.
     
    Litewebsite, Aug 27, 2006 IP
  8. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #8
    I solved the problem myself lol Thanks for all your help, I needed to explode() the array and get rid of the "" around the URL.
     
    BRUm, Aug 27, 2006 IP
  9. Litewebsite

    Litewebsite Guest

    Messages:
    26
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Good to hear that you found the problem, sometimes it's the little things that brakes the scripts.
     
    Litewebsite, Aug 27, 2006 IP
  10. gigapromoters

    gigapromoters Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    O Great.... :)
     
    gigapromoters, Sep 1, 2006 IP