我目前通過uploadify瞭解更多,米使用我的Wordpress插件。我正確地上傳了文件;它的工作是僅上傳單個.pdf文件。當我嘗試上傳同一個文件兩次,並檢查上傳文件的存儲位置時,我只有一個文件。我猜它已被覆蓋,知道文件夾中已存在文件。讓我感到困惑的是,我將如何更改第二個上傳文件(同一個文件)的文件名,以便將其導入「文件名(2)」,「文件名(3)」等內容。如果上傳的文件已經存在於目標文件夾中,則將上傳文件的文件名從'文件名'更改爲'文件名(2)'
這裏是我的代碼,見識一下我應該從哪裏開始配置對我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;
}
非常感謝。儘管我把('。++ $ i。')放在前面。使用你的方法,我的文件將不會被區分,因爲結果是這樣的,filename.ext(3),使文件類型爲未知。 BUt非常感謝..雖然.. :) – 2012-07-19 17:59:41
當然 - 我不能說'$ name'是否包含擴展名。很高興我能幫上忙! – nickb 2012-07-19 18:01:05
實際上,它確實包含了擴展名。如果我可以連接路徑+文件名+(++ $ i)+擴展名,它是否可能? – 2012-07-19 18:07:18