PHP 圖片副檔名大寫轉小寫

  • 5297
  • 0
  • PHP
  • 2013-09-27

PHP 圖片副檔名大寫轉小寫

 

程式說明:
$dir:資料夾位置
$file:檔案名稱(需包含副檔名)
strtolower() 函式:將字串轉為小寫
pathinfo(path,options)函式:path 檔案名稱;
                                                               process_sections 沒有設定默認為all,
                                                                                            PATHINFO_DIRNAME - 只返回 目錄名稱
                                                                                            PATHINFO_BASENAME - 只返回 基本名稱
                                                                                            PATHINFO_EXTENSION - 只返回 副檔名 (選這個)
 
 
程式碼如下:
 
//獲得圖片,判斷副檔名
function getDeputyFile($dir,$file){
 
    //獲得副檔名
    $deputy=pathinfo($file, PATHINFO_EXTENSION);
 
    //轉為小寫
    $deputy=strtolower($deputy);
     
     //判斷圖片副檔名
    if($deputy=='gif')
        $img=imagecreatefromgif($dir.$file);
    elseif($deputy=='jpg')
        $img=imagecreatefromjpeg($dir.$file);
    elseif($deputy=='png')
        $img=imagecreatefrompng($dir.$file);
    elseif($deputy=='bmp')
        $img=imagecreatefromwbmp($dir.$file);
 
    return $img;
}

 

 

參考或是複製語法時,別忘了留個言喔 ^ ^ ~