Okay, I have this script which is supposed to get the filetype of the file being uploaded (sent to this script from another form page), and then if the filetype is not pjepg or gif then it rejects the upload by printing an error message. Every time I upload, however, it always says the file is the wrong format, no matter what. The code is as follows:
$oquery = "SELECT FROM users WHERE user = $user";
$oresult = mysql_query($oquery);
if ($oresult) {
$oval = "else";
} else {
$oval = NULL;
}
echo $oval;
if (is_null($oval)) {
if ($oval > 1) {
$source = "icons/default.jpg";
} else {
if ($FILES['file']['type'] == "image/pjpeg"){
mysql_select_db("markar_nu-users",$db);
$query = "SELECT count() as count FROM pending";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$id = $row['count']+1;
copy ($FILES['file']['tmp_name'],"icons/".$id) or die ("Your icon failed $
$source="icons/".$id;
echo $source;
} else if ($FILES['file']['type'] == "image/gif") {
mysql_select_db("markar_nu-users",$db);
$query = "SELECT count(*) as count FROM pending";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$id = $row['count']+1;
copy ($FILES['file']['tmp_name'],"icons/".$id) or die ("Your icon failed to upload properly!");
$source="icons/".$id."gif";
} else {
echo "You have uploaded an image with an invalid file format!";
echo $_FILES['file']['type'];
$source="icons/default.jpg";
}