So I've wrote a script to upload user avatar into server and change url to it in database (thanks to YT tutorials :) ) And now I wish to make file check that user doesn't upload other files than JPG, JPEG, PNG, GIF and the ones which is bigger than 10MB. And the second thing I want to do is when user upload his avatar it removes the old one and changes name of the file to a randoom number..
So now I'm stuck a little bit and don't know where to begin could someone please help with it ? :) I could not find a usefull tutorial on google which would fit to this code as simple as possible..
The code I wrote so far;
if (isset($_POST['submit'])) {
$name = $_FILES['myfile']['name'];
$tmp_name = $_FILES['myfile']['tmp_name'];
$allowedExts = array("jpg", "jpeg", "gif", "png");
if ($name) {
$location = "uploads/avatars/$name";
move_uploaded_file($tmp_name, $location);
$query = mysql_query("UPDATE users SET avatar = '$name' WHERE id = '$session_user_id'");
echo 'Your avatar has been changed sucessfully!';
}else {
echo 'Please select a file! Following are supported; JPG, JPEG, PNG, GIF!';}