Uploadify を使用して画像をサーバーにアップロードしています。
画像がアップロードされ、Web サーバーの一時フォルダーに配置されます。
ここで、ファイルを実際の場所に移動する前にファイルを操作する必要があり、次のコードがあります。
// Get the filepath and filename from server temp dir
$sourceFile = $_FILES[ 'Filedata' ][ 'tmp_name' ]; // e.g. c:\server\path\tmp\php159.tmp
// Solution 1 for getting file extension
$fileExt1 = pathinfo($sourceFile, PATHINFO_EXTENSION); // <-- This only returns .tmp
// Solution 2 with getimagesize
list(,,$extension) = getimagesize($sourceFile);
$fileExt2 = $extension; // this only returns the number 2.
// Solution 3 with getimagesize
$img = getimagesize($sourceFile);
$fileExt3 = $img[2]; // this only returns the number 2.
ユーザーはファイルに任意の名前を付けることができるため、ファイルデータを読み取る必要があるため、ファイル名を読み取るために正規表現を使用していません。
誰か提案はありますか?