This should do the trick
https://www.tutorialspoint.com/php/php_file_uploading.htm
Note that even though it says $_FILES[‘image’] it’s not strictly for image upload, it’s simply the name they’ve chosen for the input field in the form below. If you change both those to “jimisawesome” it will still work.
It then has a check for file extension, in theory you don’t even need this but it’s always good to check that you receive what you expect, just change it to the extensions you do accept.
It then checks for a specific file size, which definitely is just to show further how to add constraints to what is acceptable to upload. You definitely don’t need this one.
If you then check the definition for move_uploaded_file you will see that it actually overwrites any existing file - as you want
Warning If the destination file already exists, it will be overwritten.
https://www.php.net/manual/en/function.move-uploaded-file.php
Things like this can be a big frustration for new coders as it’s very easy to look for a write up or tutorial on the exact issue one is working on. But when you get past that and see you can adapt things you find online to suit your use case there is an ocean of information and help out there.
The reason I’m again asking what your actual problem is - is
The XY problem is a communication problem encountered in help desk and similar situations in which the real issue, X , of the person asking for help is obscured, because instead of asking directly about issue X , they ask how to solve a secondary issue, Y , which they believe will allow them to resolve issue X . However, resolving issue Y often does not resolve issue X , or is a poor way to resolve it, and the obscuring of the real issue and the introduction of the potentially strange secondary issue can lead to the person trying to help having unnecessary difficulties in communication and offering poor solutions.
https://en.wikipedia.org/wiki/XY_problem
Since a lot of the people answering technical questions online online, be it forums, facebook or stack overflow, have some experience with these things it’s fair to question if the solution you’re trying to code is actually the best one.
I’m still not sure what you’re actually trying to achieve, but I am sure me and others here would like to pitch in on potential solutions if you take another go at explaining what this excel / html stuff you want to do is all about.