im making a social networking website and im trying to make it so that you could change your avatar, here is my code for the avatar changing process:
mysql_connect("website", "dbuser", "dbpass");
mysql_select_db("dbtable");
$upload_path = "./account/{$_SESSION["id"]}/";
$pw = $_POST['password'];
$email = $_POST['email'];
$q = mysql_query("SELECT * FROM `users` WHERE `email`='$email' AND `password`='$pw' LIMIT 1");
if(!$q) die(mysql_error());
if(mysql_num_rows($q) == 0) die("Authorization failed.");
$allowed = array('png');
$filename = $_FILES['newimage']['name'];
if(!($_FILES['newimage']['type'] == 'image/png')) {
die('The file is incorrect, only PNG files are allowed.');
}
$max_filesize = 10485760;
if(filesize($_FILES['newimage']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
if(move_uploaded_file($_FILES['newimage']['tmp_name'],"./account/".$_SESSION['id']."/profile.png"))
echo 'Successfully changed avatar.';
else
echo 'There was an error during the file upload. Please try again.';
The problem here is that it always says "The file is incorrect, only PNG files are allowed." I don't see anything wrong with this code, how would i fix this?
print_ryour$_FILESor at least$_FILES['newimage']['type']?mysql_functions have been deprecated for years now and are insecure. Also note that your code is open to SQL injection. Try to put a correct email in your login form and a wrong password. Eg.[email protected]' --(notice the' --?). Suddenly you don't even have to know the password thanks to SQL injection and you can log in as anyone. If you don't know the email, don't worry:' OR username = 'admin' --