【发布时间】:2013-04-30 03:28:18
【问题描述】:
我在 web 项目上使用 uploadify,而且我不是一个 php 高手,所以我很难理解为什么以下结果会导致上传的图像没有有效的扩展名。我得到没有 .jpg 扩展名的“1-profile”。有人能解释一下吗?
<?php
/*
UploadiFive
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
*/
// Set the uplaod directory
$uploadDir = '/img/profiles/';
// 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) {
rename($_FILES['Filedata']['name'], $_POST['user_id'].'-profile');
$tempFile = $_FILES['Filedata']['tmp_name'];
$uploadDir = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
$targetFile = $uploadDir .$_POST['user_id']. '-profile.'. strtolower($fileParts['extension']);
// 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.';
}
}
?>
【问题讨论】:
-
你说你得到
1-image没有扩展但你提供的代码不会远程创建该文件名,我有点困惑。 -
抱歉 - 我的意思不是 1-profile