我创建了一个成功上传[multiple]文件的功能。但是如果我尝试更改文件名,则文件名将被更改,但只有最后选择的文件才会上传。
这是我的代码。
<?php
$files = $_FILES['userfile'];
$dir = './uploads/';
foreach ($files['name'] as $key => $value) {
$direction = $dir . $_FILES['userfile']['name'][$key];
move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $direction);
}
?>
管理这样做
$files = $_FILES['userfile'];
$dir = './uploads/';
foreach ($files['name'] as $key => $value) {
$filename = $_FILES["userfile"]["name"][$key];
$temp = explode(".", $filename);
$newfilename = uniqid('',true).'.'.end($temp);
$direction = $dir.$newfilename;
move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $direction);
}
问题在于microtime()
答案 0 :(得分:0)
试用此代码
//load date helper
$this->load->helper('date');
$files = $_FILES['userfile'];
$dir = './uploads/';
foreach ($files['name'] as $key => $value) {
$filename = $_FILES["userfile"]["name"][$key];
$temp = explode(".", $filename);
//
$file_tempname = date('Y-m-d H:i:s');
//
$newfilename = $file_tempname.'.'.end($temp);
$direction = $dir.$newfilename;
move_uploaded_file($_FILES['userfile']['tmp_name'][$key], $direction);
}