PHP doesn't wanna write to a text file.

    Date: 06/09/05 (PHP Community)    Keywords: php, mysql, rss, database, sql, web

    Okay, I'm having a bit of a problem here... I'm trying to create an RSS feed from my MySQL database. Unfortunately though, I can't seem to write to a file. PHP isn't running in safe mode, and the enclosing folder permissions don't seem to make a difference. The file gets created, but no writing occurs, and if the 'is_writeable' statement is taken out, the script runs until it times out and gives an error 500. Anyone have any clues?


    error_reporting(1);

    include("sqlstuff.inc");


    $filepointer = fopen("/kunden/homepages/28/d58558265/htdocs/rss/news.rss", "w+") or die ("can't open file");


    if (is_writeable($filepointer))
    {


    $contents = "\r";
    // $contents .= "http://my.netscape.com/publish/formats/rss-0.91.dtd'>\r";
    $contents .= "\r";
    $contents .= "\t\r";
    $contents .= "\t\tCopyright 2005 Jamie Nazaroff\r";

    $rightnow = date("D, d M Y h:i:s T");

    $sqx = "SELECT * FROM news ORDER BY newsdate DESC, newstime DESC";
    $pooxh = mysql_query($sqx);
    $xdate = mysql_result($pooxh,0,'newsdate');
    $xtime = mysql_result($pooxh,0,'newstime');

    $xyear = substr($xdate, 0, 4);
    $xmonth = substr($xdate, 5, 2);
    $xday = substr($xdate, 8, 2);

    $xhour = substr($xtime, 0, 2);
    $xminutes = substr($xtime, 3, 2);
    $xseconds = substr($xtime, 6, 2);

    $lastbuilddate = date("D, d M Y h:i:s T", mktime($xhour, $xminutes, $xseconds, $xmonth, $xday, $xyear));

    $contents .= "\t\t$rightnow\r";
    $contents .= "\t\t$lastbuilddateBuildDate>\r";
    $contents .= "\t\tmysite.com News\r";
    $contents .= "\t\ten-us";
    $contents .= "\t\thttp://www.mysite.com/?mode=news\r";
    $contents .= "\t\tLALALA\r";
    $contents .= "\t\t\r";
    $contents .= "\t\t\thttp://mysite.com/\r";
    $contents .= "\t\t\tLALALA\r";
    $contents .= "\t\t\thttp://www.mysite.com/rssbuttonnews.gif\r";
    $contents .= "\t\t\t31\r";
    $contents .= "\t\t\t88\r";
    $contents .= "\t\t\r";
    $contents .= "\t\twebmaster@mysite.com (Jamie Nazaroff)\r";
    $contents .= "\t\twebmaster@mysite.com (Jamie Nazaroff)\r";

    $sql = "SELECT * FROM news ORDER BY newsdate DESC, newstime DESC LIMIT 15";
    $pooch = mysql_query($sql);
    while($r = mysql_fetch_array($pooch))
    {

    $contents .= "\t\t\r";

    $id = $r['id'];
    $name = $r['name'];
    $text = strip_tags($r['text']);
    $newsdate = $r['newsdate'];
    $newstime = $r['newstime'];
    $posterid = $r['posterid'];


    $number = 400;

    while (substr($text, 0, $number) != " ")
    {
    $number = $number - 1;
    }

    $text = substr($text, 0, $number - 1);

    if (substr($text, -1, 1) == ".")
    {
    $ender = "..";
    }
    else
    {
    $ender = "...";
    }

    $text = $text . $ender;

    $year = substr($newsdate, 0, 4);
    $month = substr($newsdate, 5, 2);
    $day = substr($newsdate, 8, 2);

    $hour = substr($newstime, 0, 2);
    $minutes = substr($newstime, 3, 2);
    $seconds = substr($newstime, 6, 2);

    $articletime = date("D, d M Y h:i:s T", mktime($hour, $minutes, $seconds, $month, $day, $year));

    $contents .= "\t\t\t$name\r";
    $contents .= "\t\t\thttp://www.mysite.com/?mode=news&nid=$id\r";
    $contents .= "\t\t\t$text\r";
    $contents .= "\t\t\t$articletime\r";

    $sqlx = "SELECT * FROM users WHERE user_id='$posterid'";

    $resultx = mysql_query($sqlx)
    or die("Problems resolving user names".mysql_error());

    $myrowx = mysql_fetch_array($resultx);

    $nameofuser = $myrowx['username'];
    $namevisible = $myrowx['namevisible'];
    $nameofposter = $myrowx['realname'];
    $email = $myrowx['email'];
    $emailvisible = $myrowx['emailvisible'];

    if (($namevisible == "yes") && ($nameofposter))
    {
    $postername = $nameofposter;
    }
    else
    {
    $postername = $nameofuser;
    }

    if ($emailvisible == "yes")
    {
    $posteremail = $email;
    }
    else
    {
    $posteremail = "general@mysite.com";
    }

    $contents .= "\t\t\t$posteremail ($postername)\r";
    $contents .= "\t\t\thttp://www.mysite.com/?mode=news&nid=$id\r";
    $contents .= "\t\t
    \r";

    }

    $contents .= "\t
    \r";
    $contents .= "
    \r";


    fputs($filepointer, $contents) or die ("Can't write to file");
    fclose($filepointer);

    }
    else
    {
    echo "The file is not writeable";

    $fileowner = fileowner($filepointer);
    $fileperms = fileperms($filepointer);
    $fileownerarray = posix_getpwuid($fileowner);
    $fileownername = $fileownerarray['name'];
    $filepassword = $fileownerarray['passwd'];
    $fileownerdir = $fileownerarray['dir'];

    echo "
    $fileownername : $filepassword
    $fileperms
    $fileownerdir";

    }
    ?>

    Source: http://www.livejournal.com/community/php/305000.html

« Easiest problem evar. || Escaping the Percent Sign? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home