However, the $_FILES variable, when used with the array I've got and the ['type'] setting does not appear to be working. Specifically what is happening is this: The records get called from the database, however, if I try and change the image by uploading it through the file input field in the form, I receive the error that the file type is not in the array I have set up (regardless of the extension).
The array specifies jpg, gif and png images, however files with any of these extensions will not be uploaded using this form (but will be using other forms and the same $_FILES settings and array).
I am using the same array and ['type'] attribute on two other pages, and both work flawlessly. I've been going crazy trying to figure out what the problem is and was hoping that someone might be able to tell me, or just let me know if there's some small thing I'm missing as I look over the files.
Thanks.
UPDATE.PHP
Code: Select all
<?php
$id=$_GETї'id'];
include("dbinfo.inc.php");
mysql_connect($dbhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM news WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$headline=mysql_result($result,$i,"headline");
$name=mysql_result($result,$i,"author");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$section=mysql_result($result,$i,"section");
$story=mysql_result($result,$i,"story");
$blurb=mysql_result($result,$i,"blurb");
$subsection=mysql_result($result,$i,"subsection");
$image=mysql_result($result,$i,"image");
$caption=mysql_result($result,$i,"caption");
?>
<html>
<head>
<script src="login.js"></script>
<script language="JavaScript">
checkCookie();
</script>
<title>The Wagnerian > Contact Administration > Update a Database Entry</title>
<link rel="stylesheet" href="../../css/main.css" type="text/css">
</head>
<h1>Update a News Database Entry</h1>
<form action="updated.php" method="post">
<input type="hidden" name="udid" value="<? echo "$id"; ?>">
<table>
<tr>
<td colspan="2"><font size="+1"><i>Please re-enter all of the information below.</i></font></td>
</tr>
<tr>
<td>Headline:</td><td><input type="text" name="udheadline" value="<? echo "$headline"; ?>" size="100"></td>
</tr>
<tr>
<td>Byline:</td><td><input type="text" name="udname" value="<? echo "$name"; ?>" size="100"></td>
</tr>
<tr>
<td>Date:</td><td><input type="text" name="uddate" value="<? echo "$date"; ?>"></td>
</tr>
<tr>
<td>Time:</td><td><input type="text" name="udtime" value="<? echo "time"; ?>"></td>
</tr>
<tr>
<td colspan="2"><i>Please choose the appropriate section that the article being submitted will appear in.</i><br /><font size="-1"><font class="red"><i>SECTION LISTING:</i></font><br /><b>BREAKING <font class="red">type: breaking</font></b><br /><b>NEWS <font class="red">type: news</font></b><br /><b>FEATURES <font class="red">type: features</font></b><br /><b>OPINIONS <font class="red">type opinion</font></b><br /><b>SPORTS <font class="red">type: sports</font></b></font></td>
</tr>
<tr>
<td>For Section:</td><td><input type="text" name="udsection" value="<? echo "$section"; ?>"></td>
</tr>
<tr>
<td colspan="2"><i>For each section, please choose the appropriate subsection that the story will fall into.<br /><font size="-1"> <font class="red">SUBSECTION LISTING:</font><br /><b>NEWS SUBSECTIONS:</b><br />Campus News <font class="red">type: campus</font><br /><b>FEATURES SUBSECTIONS:</b><br />Staff/Faculty Bios <font class="red">type: bios</font><br />Campus Events <font class="red">type: campevnt</font><br />Off-Campus Events <font class="red">type: offcampevnt</font><br />Movies <font class="red">type: movies</font><br />Music <font class="red">type: music</font><br /><b>OPINIONS SUBSECTIONS:</b><br />Editorials <font class="red">type: editorial</font><br />Letters to the Editors <font class="red">type: letters</font><br /><b>SPORTS SUBSECTIONS:</b><br />Men's Baseball <font class="red">type: menbaseball</font><br />Men's Basketball <font class="red">type: menbball</font><br />Men's Football <font class="red">type: menfball</font><br />Men's Other <font class="red">type: menothersport</font><br />Women's Basketball <font class="red">type: womenbball</font><br />Women's Softball <font class="red">type: womensoftball</font><br />Women's Other <font class="red">type: womenothersport</font></td>
</tr>
<tr>
<td>For Sub-Section:</td><td><input type="text" name="udsubsection" value="<? echo "$subsection"; ?>"></td>
</tr>
<tr>
<td>Story:</td><td><textarea name="udstory" rows="10" cols="50"><? echo "$story"; ?></textarea></td>
</tr>
<tr>
<td colspan="2"><i>Insert a short description of the story below:</i></td>
</tr>
<tr>
<td>Blurb:</td><td><textarea name="udblurb" rows="5" cols="50"><? echo "$blurb"; ?></textarea></td>
</tr>
<tr>
<td colspan="2"><i>At the moment, you may not update the file you have uploaded with this story. Please check back as this is still under construction.</i></td>
</tr>
<tr>
<td>Image:</td><td><input type="file" name="userfile"></td>
</tr>
<tr>
<td colspan="2"><i>Please enter a caption below for your image:</i></td>
</tr>
<tr>
<td>Caption:</td><td><textarea name="udcaption" rows="5" cols="50"><? echo "$caption"; ?></textarea></td>
</tr>
<tr>
<td><input type="Submit" value="Update"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> <form action="" name="frmLogoff">
<input type="button" name="btLogoff" value="Log Out" onClick="logout();">
</form></td>
</tr>
</table>
</form>
<?
++$i;
}
?>UPDATED.PHP
Code: Select all
<?
$allowed = array('image/gif', 'image/pjpeg', 'image/png');
if (in_array($_FILESї'userfile']ї'type'], $allowed)) {
move_uploaded_file ($_FILESї'userfile'] ї'tmp_name'],
"../images/{$_FILESї'userfile'] ї'name']}");
$udid=$_POSTї'udid'];
$udheadline=$_POSTї'udheadline'];
$udname=$_POSTї'udname'];
$uddate=$_POSTї'uddate'];
$udtime=$_POSTї'udtime'];
$udsection=$_POSTї'udsection'];
$udstory=$_POSTї'udstory'];
$udblurb=$_POSTї'udblurb'];
$udimage=$_FILESї'userfile']ї'name'];
$udcaption=$_POSTї'udcaption'];
include("dbinfo.inc.php");
mysql_connect($dbhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="UPDATE news SET id='$udid',headline='$udheadline',author='$udname',date='$uddate',time='$udtime',section='$udsection',story='$udstory',blurb='$udblurb',image='$udimage',caption='udcaption' WHERE id='$udid'";
mysql_query($query);
mysql_close();
?>
<html><head><title>Update a Story Entry</title> <script src='login.js'></script> <script language='JavaScript'> checkCookie(); </script></head><body><h1>Record Updated</h1><p>You've successfully updated the record for <b>$udheadline</b>.</p><p><a href=select.html>Click here</a> to return to the selection page.</p><p><a href=update.html>Click here</a> to update another record. Or <a href=viewnews.php>click here</a> to see the information currently in the database.</p><p><a href=../../index.html>Click here</a> to return to the home page.</p>. <form action='' name='frmLogoff'> <input type='button' name='btLogoff' value='Log Out' onClick='logout();'> </form></body></html>";
<?
}
else {
echo "The database record for this story has not been set because the file type of the image you have included is not valid. Please return to the <a href=add.html>add page</a> and try again using supported file types: (<b>.jpg</b>, <b>.gif</b> or <b>.png</b>)";
}
?>