Newsboard Trouble??
Posted: Sat Dec 18, 2004 9:35 am
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>&nbsp;</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">&nbsp;</td>
<td valign="top"><input type="submit" name="Submit" value="Submit">
<input name="Reset" type="reset" id="Reset" value="Reset"></td>
</tr>
</table>
<p>&nbsp;</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>