$uploaddir = '/stelsuser/uploads/'; //папка куда загружать
foreach($_FILES as $k=>$v){
if(move_uploaded_file($v['tmp_name'],$uploaddir.uniqid('file_', true).".txt"))
$userfileecho. = $k.' - успешно';
}
echo $userfileecho;
<?php
define('DS', DIRECTORY_SEPARATOR);
$dir = 'uploads';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$result = [];
if (isset($_FILES['files']) && $files = $_FILES['files']) {
for ($i = 0; $i <= count($files); ++$i) {
if (!empty($files['tmp_name'][$i])) {
$filename = sprintf('a4_%d.txt', $i);
$path = $dir . DS . $filename;
$result[$i] = [$filename, move_uploaded_file($files['tmp_name'][$i], $path)];
}
}
}
array_walk($result, function (&$item, $index) {
$item = '<p>' . ($index + 1) . ' - ' . $item[0] . ' - ' . ($item[1] ? 'Успешно' : 'Ошибка') . '</p>';
});
echo '<div>' . implode(PHP_EOL, $result) . '</div>';
exit;
}
?>
<form method="POST" enctype="multipart/form-data">
<p>File #1: <input type="file" name="files[]"></p>
<p>File #2: <input type="file" name="files[]"></p>
<p>File #3: <input type="file" name="files[]"></p>
<p>File #4: <input type="file" name="files[]"></p>
<p>File #5: <input type="file" name="files[]"></p>
<p>File #6: <input type="file" name="files[]"></p>
<button type="submit">Отправить</button>
</form>