Php 上载丢失的文件扩展名

Php 上载丢失的文件扩展名,php,uploadify,Php,Uploadify,我正在使用uploadify on web项目,我不是一个特别的php高手,所以我很难理解为什么下面的结果是上传的图像没有有效的扩展名。我得到了没有.jpg扩展名的“1-profile”。有人能解释一下吗 <?php /* UploadiFive Copyright (c) 2012 Reactive Apps, Ronnie Garcia */ // Set the uplaod directory $uploadDir = '/img/profiles/'; // Set

我正在使用uploadify on web项目,我不是一个特别的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.';

    }
}
?>

在定义前是否引用了
$fileParts

$targetFile = $uploadDir .$_POST['user_id']. '-profile.'. strtolower($fileParts['extension']);

// Validate the filetype
$fileParts = pathinfo($_FILES['Filedata']['name']);
应该是

$fileParts = pathinfo($_FILES['Filedata']['name']);
$targetFile = $uploadDir .$_POST['user_id']. '-profile.'. strtolower($fileParts['extension']);

// Validate the filetype

你说你得到的是没有扩展名的
1-image
,但是你提供的代码无法远程创建该文件名,我有点困惑。对不起,我的意思是不是1-profiles谢谢!很简单,但我看不见!:)PHP会对此发出警告。您可能希望在开发计算机上启用错误报告,以使这些问题更易于调试: