我正在使用uploadify,但我不太清楚如何編輯php來重命名上傳的文件。Uploadify - 重命名文件
基本上,用戶最多可以上傳4個文件,它們應該被命名爲像1-img-1,1-img-2,1-img-3,1-img-4 - 第一個數字是用戶id(可以通過POST訪問)。
這裏的uploadify PHP腳本:
<?php
/*
UploadiFive
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
*/
// Set the uplaod directory
$uploadDir = '/img/listing_images/';
// Set the allowed file extensions
$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
if (!empty($_FILES) && $_POST['token'] == $verifyToken) { $i++;
$tempFile = $_FILES['Filedata']['tmp_name'];
$uploadDir = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
$targetFile = $uploadDir . $_FILES['Filedata']['name'];
// Validate the filetype
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array(strtolower($fileParts['extension']), $fileTypes)) {
// Save the file
move_uploaded_file($tempFile, $targetFile);
echo 1;
} else {
// The file type wasn't allowed
echo 'Invalid file type.';
}
}
?>
只是想知道,如果有人可以幫告訴我我怎麼會重命名上傳的文件?
您的腳本將允許您的服務器完全泄露,特別是如果$ uploadDir位於您的文檔根目錄中。你的「安全」不過是。用戶提供的文件名進行過濾是**不夠**。 –