I Am Zang (zang) wrote in php,
I Am Zang
zang
php

  • Music:

PHP doesn't wanna write to a text file.

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?


<?php
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 = "<?xml version='1.0'?>\r";
// $contents .= "<!DOCTYPE rss SYSTEM 'http://my.netscape.com/publish/formats/rss-0.91.dtd'>\r";
$contents .= "<rss version='2.0'>\r";
$contents .= "\t<channel>\r";
$contents .= "\t\t<copyright>Copyright 2005 Jamie Nazaroff</copyright>\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<pubDate>$rightnow</pubdate>\r";
$contents .= "\t\t<lastBuildDate>$lastbuilddate</lastBuildDate>\r";
$contents .= "\t\t<description>mysite.com News</description>\r";
$contents .= "\t\t<language>en-us</language>";
$contents .= "\t\t<link>http://www.mysite.com/?mode=news</link>\r";
$contents .= "\t\t<title>LALALA</title>\r";
$contents .= "\t\t<image>\r";
$contents .= "\t\t\t<link>http://mysite.com/</link>\r";
$contents .= "\t\t\t<title>LALALA</title>\r";
$contents .= "\t\t\t<url>http://www.mysite.com/rssbuttonnews.gif</url>\r";
$contents .= "\t\t\t<height>31</height>\r";
$contents .= "\t\t\t<width>88</width>\r";
$contents .= "\t\t</image>\r";
$contents .= "\t\t<webMaster>webmaster@mysite.com (Jamie Nazaroff)</webMaster>\r";
$contents .= "\t\t<managingEditor>webmaster@mysite.com (Jamie Nazaroff)</managingEditor>\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<item>\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<title>$name</title>\r";
$contents .= "\t\t\t<link>http://www.mysite.com/?mode=news&nid=$id</link>\r";
$contents .= "\t\t\t<description>$text</description>\r";
$contents .= "\t\t\t<pubDate>$articletime</pubDate>\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<author>$posteremail ($postername)</author>\r";
$contents .= "\t\t\t<guid>http://www.mysite.com/?mode=news&nid=$id</guid>\r";
$contents .= "\t\t</item>\r";

}

$contents .= "\t</channel>\r";
$contents .= "</rss>\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 "<br>$fileownername : $filepassword<br>$fileperms<br>$fileownerdir";

}
?>
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 17 comments