i edited this code alot of times (im noob whit php) and my problem is upload multiples files with this code. i can upload only 1 file.
Here
To successfully send multiple files from you're browser, you need your inputs to pass an array to PHP. This is done by appending [] to the end of your s name:
Processing these files is the tricky part. PHP handles file uploads differently than it would handle other POST or GET data provided in an array. File uploads have a metadata key inserted between the input's name, and the index of the file that was uploaded. So $_FILES['filesToUpload']['name'][0] will get the name of the first file, and $_FILES['filesToUpload']['name'][1] will get the name of the second file... and so on.
Because of this foreach is absolutely the wrong loop to use. You will end up processing each piece of metadata on it's own, without any context. That's dreafully unnatural.
Let's get the index of each file and process one file at a time instead. We'll use a for loop for this. This is an entirely self contained, functioning example of a user uploading multiple files to a folder on the server:
To run this example, your files should look like this
You can startup the PHP builtin webserver with:
$ php -S localhost:8000
Then going to http://localhost:8000/sandbox.php will run the example.
Important note: The above example does not do any validation. You will need to validate that all the uploaded files are safe.