Newsboard Trouble??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Newsboard Trouble??

Post by mmc01ms »

I've created a simple newsboard for a website using the principles of creating a web-blog. Im having trouble as when i enter the image file i want to be uploaded and press submit the output is that i have not specifed a file which i have. code for html and php is below. However i have also used the $file_name = $_POST['file']; method and that doesn't work either.

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Newsboard Entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<table width="634" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr> 
    <td width="634" height="455" valign="top"><form action="writetonewsboard.php" method="post" enctype="multipart/form-data">
        <p> </p>
        <table width="512" border="0" cellspacing="2" cellpadding="2">
          <!--DWLayoutTable-->
          <tr> 
            <td height="42" align="right" valign="top">Entry Title</td>
            <td width="398" valign="top"><input type="text" name="title" id="title" size="45"></td>
          </tr>
          <tr> 
            <td height="218" align="right" valign="top">Story</td>
            <td valign="top"><textarea name="story" id="story" cols="60" rows="12"></textarea></td>
          </tr>
          <tr> 
            <td height="42" align="right" valign="top">Image Upload </td>
            <td valign="top"><input type="file" name="file"></td>
          </tr>
          <tr> 
            <td width="100" height="23"> </td>
            <td valign="top"><input type="submit" name="Submit" value="Submit">
              <input name="Reset" type="reset" id="Reset" value="Reset"></td>
          </tr>
        </table>
        <p> </p>
      </form></td>
    </tr>
</table>
</body>
</html>

Code: Select all

<?php
	
	
	
if($file_name !="")
	{
		@copy("$file","../images/$file_name")
		or die("Couldn't copy the file.");
	}
	else
	{
		die("No input file specfied");
	}
$filename="newsboard.html";
$oldfile=fopen($filename, "r");
$file_content=fread($oldfile, filesize($filename));
fclose($oldfile);

$date = (date("d-m-Y"));
//$time = (date("H:i:s"));
$f = fopen($filename, "w+");

fwrite($f,"<table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#6699cc">\r\n");
fwrite($f, "<td width="70%"><font color="#000000" size="2" face="arial,helvetica,sans-serif">$date</font></td>\r\n");
//fwrite($f "<td><font size="2" face="arial,helvetica,sans-serif">$time</font></td>\r\n");//this line of code doesn't work!!!
fwrite($f, "</tr>\r\n");
fwrite($f, "<table>\r\n");
fwrite($f, "<table width="100%" border="0" cellspacing="0" cellpadding="2">\r\n");
fwrite($f, "<tr>\r\n");

fwrite($f, "<td width="200" valign="top"><img src="$file_name"></td>\r\n");
fwrite($f, "<td valign="top"><font color="#333366" size="3" face="arial, helvetica, sans-serif"><strong>$title<br>\r\n");
fwrite($f, "</strong><font color="#000000" size="2">$story</font></font></td>\r\n");
fwrite($f, "</tr>\r\n");
fwrite($f, "</table><br>\r\n");

fwrite($f, "\r\n");
fwrite($f, "$file_content");
fclose($f);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Write To Newsboard</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<table width="634" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr> 
    <td width="634" height="455" valign="top"><p><font face="Arial, Helvetica, sans-serif">Submit 
        Successful</font></p>
      <p><font face="Arial, Helvetica, sans-serif">You Sent: <? echo "$file_name"; ?>, 
        a <? echo "$file_size";?> byte file of a mime type <? echo "$file_type"; ?> 
        <a href="newsboard.html">See Newsboard</a></font></p></td>
  </tr>
</table>
</body>
</html>
mmc01ms
Forum Commoner
Posts: 97
Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK

Post by mmc01ms »

any ideas?
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

looks like your relying on register globals, maybe it is turned off.

you need to use $_POST and $_FILES for all your variables which result from your form
Post Reply