Here is an example PHP program to upload files.
<?php
$target_dir = "uploads/"; // This directory should be accessible and writable for the web server.
echo "The number of files to upload is " . count($_FILES['fileToUpload']['name']) . '.<br>'; // full path
// 'fileToUpload[]' is the name of file type input in the client code.
for ($i = 0; $i < count($_FILES['fileToUpload']['name']); $i++) {
$target_file = $target_dir . basename($_FILES['fileToUpload']['name'][$i]); // basename() - just file name
if (!file_exists($target_file)) {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"][$i], $target_file))
echo "The file " . basename( $_FILES["fileToUpload"]["name"][$i]) . " has been uploaded.<br>";
else
echo "Sorry, there was an error uploading your file.<br>";
} else
echo $target_file . ' already exists.<br>';
}
?>