古詩詞大全網 - 成語解釋 - function_exists的實例

function_exists的實例

//判斷gif函數是否存在

if(function_exists(imagegif))

{

//如果存在,以gif格式輸出

header(content-type: image/gif);

imagegif($im);

}

//判斷jpeg函數是否存在

elseif(function_exists(imagejpeg))

{

//如果存在,以jpg格式輸出

header(content-type: image/jpeg);

imagejpeg($im, , 0.5);

}

//判斷png函數是否存在

elseif (function_exists(imagepng))

{

//如果存在,以png格式輸出

header(content-type: image/png);

imagepng($im);

}

//判斷wbmp函數是否存在

elseif (function_exists(imagewbmp))

{

//如果存在,以bmp格式輸出

header(content-type: image/vnd.wap.wbmp);

/*

header() 函數向客戶端發送原始的 http 報頭。

認識到壹點很重要,即必須在任何實際的輸出被發送之前調用 header() 函數(在 php 4 以及更高的版本中,您可以使用輸出緩存來解決此問題):

*/

imagewbmp($im);

}

else

{

//如果都不支持,輸出內容

die(no image support in this php server);

}