0

I can't seem to move the uploaded file to the specified folder . please help, i don't know what the problem is every variables are working fine it's just that function. and also the folder have permission for everyone to modify it.

  $avatar_name = $_FILES['server_avatar']['name'];
  $avatar_tmp = $_FILES['server_avatar']['tmp_name'];

  $avatar_explode = explode(".", $avatar_name);
  $avatar_ext = end($avatar_explode);

  $extensions = ['jpg', 'jpeg', 'png', 'gif'];

  if(in_array($avatar_ext, $extensions) === true) {
    $new_avatar_name = $uniqueid.$avatar_name;

    if(move_uploaded_file($avatar_tmp, "server_avatars/".$new_avatar_name)) {
    $avatar_path = "./server_avatars/".$new_avatar_name;

    $user_id = $row['unique_id'];
    $create_server = mysqli_query($conn, "INSERT INTO servers (user_id, server_id, server_name, server_avatar) VALUES ('{$user_id}', '{$uniqueid}', '{$server_name}','{$avatar_path}')");
} else {
  echo "Something went wrong while uploading your file";
}
GMG
  • 1
  • 1
  • Do you have an error that you can post? We need more than "it's not working" because that could mean anything – Kwright02 Jul 24 '22 at 17:36
  • Warning. You should use `$avatar_name = basename($_FILES['server_avatar']['name']);` to prevent path injection. – Markus Zeller Jul 24 '22 at 17:39
  • Check if [move_uploaded_file()](https://www.php.net/manual/en/function.move-uploaded-file.php) returns true. If not see the error message in the logs. – Markus Zeller Jul 24 '22 at 17:41

0 Answers0