uploadify.php中的explode()出现问题


Having trouble with explode() in uploadify.php

我的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);
// this portion here will be true if and only if the file name of the uploaded file does not contain '.', except of course the dot(.) before the file extension
$count = 1;
list( $filename, $ext) = explode( '.', $name, );
$newTargetFile = $targetFolder . $filename . '.' . $ext;
while( file_exists( $newTargetFile)) {
    $newTargetFile = $targetFolder . $filename . '(' . ++$count . ')' . '.' . $ext;
}
// Validate the file type
$fileTypes = array('pdf'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
    move_uploaded_file($tempFile,$newTargetFile);
    echo $newTargetFile;
} else {
    echo 'Invalid file type.';
}
return $newTargetFile;
}

基本上这是相当有效的。上传文件并获取文件的路径,然后将其插入数据库等等。但是,我尝试上传一个文件名看起来像这样的文件,

filename.1.5.3.pdf

当成功上传时,文件名变成了单独的filename,没有文件扩展名,更不用说文件名是不完整的。据我所知,问题出在我的explode()上。它分解了具有分隔符'.'的字符串,然后将其分配给变量。我该怎么做才能使explode()将字符串一分为二,其中前半部分是文件名,第二部分是文件扩展名?P请提供帮助。

不要使用爆炸,使用为作业设计的函数:pathinfo()

$ext = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION);