我需要添加一些錯誤檢查功能以確保imagegif()和imagecolorset()函數成功。通常的失敗原因是spot2.gif文件不可寫的權限問題。幫助將錯誤檢查添加到此功能
但是,當我將spot2.gif更改爲只讀,應觸發「其他」條件的條件時,echo'd javascript警報不會觸發。
function set_theme_color_spot2($hex)
{
$info = hexToRGB($hex);
$token = "../wp-content/themes/".get_option('template')."/styles/".get_option('myTheme')."/spot2.gif";
$token2 = "../wp-content/themes/".get_option('template')."/styles/".get_option('myTheme')."/spot2-template.gif";
if (file_exists($token2) && is_writable($token))
{
$img = imagecreatefromgif("../wp-content/themes/".get_option('template')."/styles/".get_option('myTheme')."/spot2-template.gif");
$color = imagecolorallocate($img, $info["red"], $info["green"], $info["blue"]);
imagecolorset($img, 0, $info["red"], $info["green"], $info["blue"]);
imagegif($img, $token);
$themecolor = get_option('myTheme').'_color4';
update_option($themecolor, $hex);
}
else
{
echo "<script type='text/javascript'>alert('The template colors could not be changed because your current file permissions are too restrictive. Make sure the files in the styles directory are set to 644');</script>";
}
}
這對我來說非常有意義。我已經更新了我的問題,並在條件塊中添加了is_writable檢查。然而,它仍然在執行,即使當spot2.gif被手動設置爲只讀時...任何想法? – 2010-10-14 16:47:59