I'm creating an avatar upload and I'm passing the file name through JQuery where I then want to process and resize it in an external php file and send the path to a database. I've created the form and when I send it adds the path to the database but will not recognise that a file has been uploaded in the initial php. Here is my code for getting the file name and running it through php:
The code on the profile page:
var avatar=$("#avatar").val();
var name=$("#name").val();
var location=$("#location").val();
var about=$("#about").val();
var visible = ( $("#visible").is(":checked") ) ? "checked" : "not checked";
if(nameok == true || name.value > 2)
{
$('.userValidation').html("Processing").removeClass("error").addClass("success");
jQuery.post("php/update-user-profile.php", {
avatar:avatar,
name:name,
location:location,
about:about,
checked:visible
}, function(data, textStatus){
if(data == 1){
$('.userValidation').html("Updated Successfully").removeClass("error").addClass("success");
window.location = 'home.php';
}
else{
$('.userValidation').html("Something's Wrong, Please Try Again").removeClass("success").addClass("error");
}
});
}
The code on "php/update-user-profile.php":
//Avatar Preferences
$avatar = mysqli_real_escape_string($con, $_REQUEST["avatar"]);
$fileName = $_FILES["$avatar"]["name"]; // The file name
How can I get it to recognise $avatar as a legitimate file?