我目前正在通过 uploadify 了解更多信息,顺便说一句,这就是我在 Wordpress 插件上使用的。我正确上传了文件;它的工作是仅上传单个 .pdf 文件。当我尝试两次上传相同的文件并检查将存储上传文件的文件夹时,我只有一个文件。我猜它被覆盖知道该文件已经存在于文件夹中。让我烦恼的是,我将如何更改第二个上传文件(同一个文件)的文件名,使其变为“文件名(2)”、“文件名(3)”等等。
这是我的代码,请告诉我应该从哪里开始配置uploadify.php:
if (!empty($_FILES)) {
$name = $_FILES['Filedata']['name'];
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
$path = pathinfo($targetFile);
$newTargetFile = $targetFolder.$name;
// Validate the file type
$fileTypes = array('pdf'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
// i think somewhere here , will i put something, but what's that something?
move_uploaded_file($tempFile,$newTargetFile);
echo $newTargetFile;
} else {
echo 'Invalid file type.';
}
return $newTargetFile;
}