我使用Uploadify上傳到服務器上的圖像。
圖像上傳並放置在Web服務器的臨時文件夾中。沒能獲得圖像文件的擴展
現在我需要用文件的工作beore將其移動到它的真正位置,我有以下代碼:
// 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.
我不使用正則表達式來讀取文件名
,因爲用戶可能命名文件任何東西,所以我必須讀取文件數據。
任何sugegstions人嗎?
啊,所以這就是2意味着:)謝謝。 – Steven 2009-12-12 18:54:13
我無法使用exif_imagetype,至少不是在我自己的計算機上。它沒有與我的PHP編譯(我使用v5.x)。我只接受'調用未定義的函數exif_imagetype()'。 (見下文我的評論鏈接) – Steven 2009-12-12 19:00:11
如果您在Windows然後啓用以下順序擴展=中php_mbstring.dll 延長= php_exif.dll的dll,並確保我們正在編輯正確的php.ini文件。 – kta 2012-04-08 14:01:30