Location: PHPKode > projects > MegaBB > avatarupload.php
<?php

$connection = require("dbconnect.php")

$MAXFILESIZE = 80;

if(($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "image/jpg")){
if($_FILES["file"]["size"] < $MAXFILESIZE*1024){
if($_FILES["file"]["error"] > 0){
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}else{
if(file_exists("upload/" . $_FILES["file"]["name"])){
echo $_FILES["file"]["name"] . " already exists. ";
}else{
$fileformat = explode("/",$_FILES["file"]["type"]);
$fileformat = $fileformat[1];

$filename = mysql_fetch_array(mysql_query("SELECT * FROM files ORDER BY count DESC"));
$filename = ($filename['count']+1)."." . $fileformat;

$user = $_COOKIE['cookname'];

mysql_query("UPDATE users SET avatar='$filename' WHERE username='$user'");
mysql_query("INSERT INTO files (filename) VALUES ('$filename')");

move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/avatars/" . $filename);

echo "Avatar uploaded!";
}
}
}else{
echo "File must be smaller than ".$MAXFILESIZE."Kb.";
}
}else{
echo "Invalid filetype.";
}
mysql_close($connection);
?>
Return current item: MegaBB