Error on fopen, but can I work around it?

Discussion in 'PHP' started by miko67, Jan 7, 2007.

  1. #1
    My Site Sift Directory is giving me a headache. Included is a sitemap.xml generator script that keeps failing me. The error message I get is like this:

    and:
    Fact is: I cannot get my host to activate fopen!

    My question is this: Can I work my way around it somehow?
    Any pointers would be greatly appreciated!

    
    [B][SIZE=1][COLOR=#008000]class[/COLOR][/SIZE][/B][SIZE=1] [B]GoogleSitemap[/B] [/SIZE][SIZE=1][COLOR=#008000]{[/COLOR][/SIZE]
     
    [B][SIZE=1][COLOR=#008000]function[/COLOR][/SIZE][/B][SIZE=1] [B]GoogleSitemap[/B][/SIZE][SIZE=1][COLOR=#008000]()[/COLOR][/SIZE]
    [SIZE=1][COLOR=#008000]{[/COLOR][/SIZE]
    [SIZE=1][B]$this[/B][/SIZE][SIZE=1][COLOR=#008000]->[/COLOR][/SIZE][B][SIZE=1]buildSitemap[/SIZE][/B][SIZE=1][COLOR=#008000]();[/COLOR][/SIZE]
    [SIZE=1][COLOR=#008000]}[/COLOR][/SIZE]
     
    [B][SIZE=1][COLOR=#008000]function[/COLOR][/SIZE][/B][SIZE=1] [B]buildSitemap[/B][/SIZE][SIZE=1][COLOR=#008000]()[/COLOR][/SIZE]
    [SIZE=1][COLOR=#008000]{[/COLOR][/SIZE]
    [SIZE=1][B]require_once[/B][/SIZE][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][I][SIZE=1]'../../Connections/myconn.php'[/SIZE][/I][SIZE=1][COLOR=#008000]);[/COLOR][/SIZE]
    [SIZE=1][B]mysql_select_db[/B][/SIZE][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][B][SIZE=1]$database_myconn[/SIZE][/B][SIZE=1][COLOR=#008000],[/COLOR][/SIZE][SIZE=1] [B]$myconn[/B][/SIZE][SIZE=1][COLOR=#008000]);[/COLOR][/SIZE]
    [SIZE=1][B]$settings[/B] [/SIZE][SIZE=1][COLOR=#008000]=[/COLOR][/SIZE][SIZE=1] [B]mysql_fetch_assoc[/B][/SIZE][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][B][SIZE=1]mysql_query[/SIZE][/B][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][I][SIZE=1]"select * from settings where id = '1'"[/SIZE][/I][SIZE=1][COLOR=#008000],[/COLOR][/SIZE][B][SIZE=1]$myconn[/SIZE][/B][SIZE=1][COLOR=#008000]));[/COLOR][/SIZE]
    [SIZE=1][B]$fileName[/B] [/SIZE][SIZE=1][COLOR=#008000]=[/COLOR][/SIZE][SIZE=1] [I]'../../sitemap.xml'[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$f[/B][/SIZE][SIZE=1][COLOR=#008000]=@[/COLOR][/SIZE][B][SIZE=1][COLOR=red]fopen[/COLOR][/SIZE][/B][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][B][SIZE=1]$fileName[/SIZE][/B][SIZE=1][COLOR=#008000],[/COLOR][/SIZE][I][SIZE=1]"w"[/SIZE][/I][SIZE=1][COLOR=#008000]);[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]'<?xml version="1.0" encoding="UTF-8"?>'[/I][/SIZE][SIZE=1][COLOR=#008000].[/COLOR][/SIZE][SIZE=1] [I]"\n"[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]"<!-- generator=\"Site-Sift Listings/1.11\" -->\r\n"[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]'<!-- sitemap-generator-url="'[/I][/SIZE][SIZE=1][COLOR=#008000].[/COLOR][/SIZE][B][SIZE=1]$settings[/SIZE][/B][SIZE=1][COLOR=#008000][[/COLOR][/SIZE][I][SIZE=1]'domain'[/SIZE][/I][SIZE=1][COLOR=#008000]].[/COLOR][/SIZE][I][SIZE=1]'" sitemap-generator-version="0.1.1" -->'[/SIZE][/I][SIZE=1][COLOR=#008000].[/COLOR][/SIZE][I][SIZE=1]"\r\n"[/SIZE][/I][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">[/I][/SIZE]
    [I][SIZE=1]<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'[/SIZE][/I][SIZE=1][COLOR=#008000].[/COLOR][/SIZE][SIZE=1] [I]"\n"[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]"\t<url>\r\n"[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]"\t\t<loc>"[/I][/SIZE][SIZE=1][COLOR=#008000].[/COLOR][/SIZE][B][SIZE=1]$settings[/SIZE][/B][SIZE=1][COLOR=#008000][[/COLOR][/SIZE][I][SIZE=1]'domain'[/SIZE][/I][SIZE=1][COLOR=#008000]].[/COLOR][/SIZE][I][SIZE=1]"</loc>\r\n"[/SIZE][/I][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]"\t\t<changefreq>monthly</changefreq>\r\n"[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]"\t\t<priority>1.0</priority>\r\n"[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$str[/B] [/SIZE][SIZE=1][COLOR=#008000].=[/COLOR][/SIZE][SIZE=1] [I]"\t</url>\r\n"[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
     
    [SIZE=1][B]$query_cat[/B] [/SIZE][SIZE=1][COLOR=#008000]=[/COLOR][/SIZE][SIZE=1] [I]"SELECT * FROM categories /*WHERE active = 'Yes'*/ ORDER BY title ASC"[/I][/SIZE][SIZE=1][COLOR=#008000];[/COLOR][/SIZE]
    [SIZE=1][B]$cat[/B] [/SIZE][SIZE=1][COLOR=#008000]=[/COLOR][/SIZE][SIZE=1] [B]mysql_query[/B][/SIZE][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][B][SIZE=1]$query_cat[/SIZE][/B][SIZE=1][COLOR=#008000],[/COLOR][/SIZE][SIZE=1] [B]$myconn[/B][/SIZE][SIZE=1][COLOR=#008000])[/COLOR][/SIZE][SIZE=1][COLOR=#008000]or[/COLOR][/SIZE][SIZE=1] [B]die[/B][/SIZE][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][B][SIZE=1]mysql_error[/SIZE][/B][SIZE=1][COLOR=#008000]());[/COLOR][/SIZE]
    [SIZE=1][B]$cat_count[/B] [/SIZE][SIZE=1][COLOR=#008000]=[/COLOR][/SIZE][SIZE=1] [B]mysql_num_rows[/B][/SIZE][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][B][SIZE=1]$cat[/SIZE][/B][SIZE=1][COLOR=#008000]);[/COLOR][/SIZE]
    [B][SIZE=1][COLOR=#008000]while[/COLOR][/SIZE][/B][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][B][SIZE=1]$category[/SIZE][/B][SIZE=1][COLOR=#008000]=[/COLOR][/SIZE][SIZE=1] [B]mysql_fetch_assoc[/B][/SIZE][SIZE=1][COLOR=#008000]([/COLOR][/SIZE][B][SIZE=1]$cat[/SIZE][/B][SIZE=1][COLOR=#008000]))[/COLOR][/SIZE][SIZE=1][COLOR=#008000]{[/COLOR][/SIZE]
     
    
    Code (markup):
     
    miko67, Jan 7, 2007 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    There is a work around that might work for you. I can't recall the details.

    Go to Dreamhost.com and search in their wiki
     
    Colbyt, Jan 7, 2007 IP
  3. chikabc

    chikabc Peon

    Messages:
    19
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    From the first error, i can see that the Url file access is not set to yess in php.ini.

    I would do this on top of my script:
    ini_set("allow_url_fopen" , 1);
     
    chikabc, Jul 19, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    ^ This value can't be changed via ini_set().
     
    nico_swd, Jul 19, 2007 IP
  5. chikabc

    chikabc Peon

    Messages:
    19
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I am using php5 and it seems to be working

    Are you seriouse??????

    http://pear.php.net/bugs/bug.php?id=2458
     
    chikabc, Jul 19, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    nico_swd, Jul 19, 2007 IP
  7. shanX

    shanX Peon

    Messages:
    490
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I faced a similar problem:

    Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration...

    Googled and landed here and few other pages, and found a CURL solution and it works:

    
    <?php
    /*
       * @return string
       * @param string $url
       * @desc Return string content from a remote file
       * @author Luiz Miguel Axcar (lmaxcar{AT}yahoo.com.br)
    */
    
    function get_content($url)
    {
        $ch = curl_init();
    
        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_HEADER, 0);
    
        ob_start();
    
        curl_exec ($ch);
        curl_close ($ch);
        $string = ob_get_contents();
    
        ob_end_clean();
        
        return $string;     
    }
    
    #usage:
    $content = get_content ("http://www.php.net");
    var_dump ($content);
    ?> 
    
    Code (markup):
    http://au2.php.net/manual/en/function.fopen.php#55922

    I posted this here, incase someone faced a similar problem ;)
     
    shanX, Jul 24, 2007 IP