我想使用time()
将上传文件的名称更改为当前时间,但我似乎无法确定插入新时间名称的位置?
可以尝试一下吗?
<?php
if (!empty($_FILES)) {
$newName = time(); <-- Should be the new temp name, insted of the uploaded one.
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
}
echo '1';
?>
答案 0 :(得分:1)
$_FILES['Filedata']['name']
有你的文件名,你可以替换它,但首先你需要得到文件的扩展名,如果它一直不一样。
$p = pathinfo($_FILES['Filedata']['name']);
$newName = time() . "." . $p['extension'];
$targetFile = str_replace('//','/',$targetPath) . $newName;
答案 1 :(得分:0)
// Get the extension of the uploaded file ..
$ext = end(explode('.', $_FILES['Filedata']['name']));
// Set the target location to your filename, plus the extension
$targetFile = str_replace('//','/',$targetPath) . $newName . '.' . $ext;
答案 2 :(得分:0)
代码应为:
<?php
if (!empty($_FILES)) {
$newName = time(); <-- Should be the new temp name, insted of the uploaded one.
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $newName . '.EXT';
move_uploaded_file($tempFile,$targetFile);
}
echo '1';
?>
答案 3 :(得分:0)
将$_FILES['Filedata']['name']
替换为time()