Page 1 of 1

Looking how to fix this error

Posted: Mon Jan 07, 2008 10:16 pm
by irishmike2004
Greetings:

A client of mine changed hosting services and one of my scripts broke. This is a straightforward script that uses the function file_get_contents($url); where url is a URL on the net.

The error when using debug

Code: Select all

function debug()
{
	ini_set('display_errors', 1);
	error_reporting(E_ALL);
}
returns this:

Warning: file_get_contents(http://del.icio.us/feeds/js/tags/handuma) [function.file-get-contents]: failed to open stream: Permission denied in /home/u3/eateam/html/deltags.php on line 24

This script works fine from both my dev machine and my personal web server on FreeBSD 6.2 and both are PHP version 5.2.4 where my client's machine is version 5.2.1 under FBSD 6.1

Hope someone can tell me how we fix this.

Thanks,

Mike

Posted: Tue Jan 08, 2008 3:23 am
by alex.w474
The error clearly says that the file cannot be opened because of unsufficient permissions. Tell your client that the file permissions should be changed either by using telnet/ssh, control panel (cPanel) or something so.

google for cpanel change permissions, for example.

Posted: Tue Jan 08, 2008 6:05 am
by Maugrim_The_Reaper
It's probably because HTTP access through file_get_contents() is restricted by the host. Replacing the call with something based on http or curl to fetch the url would both fix the issue, and likely prevent any future issues. PEAR for example has a HTTP_Request class that could help here (if direct curl/http use is not desireable).

I think the php.ini setting for this restriction is allow_url_fopen which should be 1, but is often set to 0 on hosts.

Posted: Tue Jan 08, 2008 7:31 am
by irishmike2004
@maugrim:

Could you provide an example of how I would fetch the URL with the http request?

here is the full script as it sits right now:

Code: Select all

<?php

//error reporting

debug();

function debug()
{
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
}


function getDelTags($userName)
{
    //Del.icio.us User Name
    $userId = $userName;

    //limit the number of tags shown
    $limit = 25;

    //process the JS feed (TagRoll)
    $url = "http://del.icio.us/feeds/js/tags/".$userId;
    $read = file_get_contents($url);

    //run the match and build the tags array
    $match = '/"(.*?)":/';
    preg_match_all($match, $read, $tags);
    $tags = $tags[1];

    //count of the number of elements in the tags array
    $tagCount = count($tags);

    //impose the limit on the array

    if($tagCount > $limit && $limit != 0){

        $startCut = $limit -1;
        
        for($i=$tagCount;$i != $startCut;$i--){
            unset($tags[$i]);
        }
    }

    //this is a temporary echo statement to check number of tags
    //echo 'Tag Count is '.$tagCount.'<br />'; 

    //process for output
    echo '<LINK REL="StyleSheet" HREF="deltags.css" TYPE="text/css">'; //remove me when CSS is transferred to ea2007.css
    echo'<div class="delicious-tags" id="delicious-tags-'.$userId.'"><ul class="delicious-cloud">TAGS: ';

    foreach ($tags as $tag) {
        echo '<li class="delicous-tags"><a href="http://del.icio.us/'.$userId.'/'.$tag.'">'.$tag.'</a></li>';
    }

    echo '</ul></div>';
}
getDelTags(handuma);
?>
thanks for your help in advance :-)

Mike

@everyone

Thanks for the suggestions. I have gone ahead and had my client check the permissions via cpanel and the setting in PHP.INI as well.