Seems like it would have been easier to replace the file with the selected file with the same name and then
refresh the link? But anyways, the posted code will get you the results you wanted.