douzuan5365 2010-10-14 16:15
浏览 27
已采纳

帮助将错误检查添加到此功能

I need to add some error checking to this function to make sure that the imagegif() and imagecolorset() functions are successful. The usual cause for failure is a permissions issue where the spot2.gif file is not writable.

However, when I change the spot2.gif to read only, a condition that should trigger the "else" conditions, the echo'd javascript alert is not firing.

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>";
    }
}
  • 写回答

2条回答 默认 最新

  • dousha1831 2010-10-14 16:20
    关注

    Why not call "is_writable" on your spot2.gif before trying to access it?

    http://php.net/manual/de/function.is-writable.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制