GD PHP Base64图片(png)错误

时间:2010-06-12 12:48:02

标签: php mysql gd

这是我的代码的一部分:

$con = mysql_connect("localhost","username","passs");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("database", $con);
if(mysql_num_rows(mysql_query("SELECT name FROM xbox_user WHERE name = '$user'"))){
    // Code inside if block if userid is already there
    $result = mysql_query("SELECT name FROM xbox_user WHERE name = '$user'");

    while($row = mysql_fetch_array($result))
    {
        if ($row['date'] > $row['date']+100){
            $src = imagecreatefrompng($result['XboxInfo']['TileUrl']);
            $base64= base64_encode(file_get_contents($result['XboxInfo']['TileUrl']));
            $date = date("Ymd");
            mysql_query("UPDATE xbox_user SET date = '$date' SET avatar = '$base64' WHERE name = '$user'");
        }else{
            $encode = $row['avatar'];
            //echo $encode;
            $rand = rand(1, 1337);
            file_put_contents('/tmp/'.$rand.'.png', base64_decode($row['avatar'])); //ERROR LINE
            $src = imagecreatefrompng('/tmp/'.$rand.'.png');
            unlink('/tmp/'.$rand.'.png');
        }
    } 
}else{
    $src = imagecreatefrompng($result['XboxInfo']['TileUrl']);
    $base64= base64_encode(file_get_contents($result['XboxInfo']['TileUrl']));
    $date = date("Ymd");
    mysql_query("INSERT INTO xbox_user (name, avatar, date)
    VALUES ('$user', '$base64', '$date')");
}

它出现了多个错误,但我觉得应该首先解决这个错误,因为另一个错误可能是由于第一个错误造成的:

Warning: imagecreatefrompng() [function.imagecreatefrompng]: '/tmp/628.png' is not a valid PNG file in /home/nah/public_html/experiment/xbox/draw3.php  on line 60

它还会在我的mysql DB中创建一个条目

这是它放在头像下的mysql中的base64,并试图解码:

iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAY1ElEQVR4nKWbSZMl13Xff3fIN9Y8NHpAo9FoTAQHEKIpUBQJUISCQVEmRUsLSVaEFmY4bIcd4Q9gL/gdHOGdNlrIGy8cYVsmFaYtkuYACCAJEGig0ewB6KF6qPnVGzLz3nO8uJnvvaquKjSpjMjI8eXL8z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wyHIax8PwGADAGewLI8WtV6j4ARBX+xoVQYr23Ns0Cs5mj0cro7Q4oQ0ge0hsQsAjWCY0sw2UZ1qXBE0P6uiSqYiSA8YxGBSEGgkTOLc2zMOu4dXd7QvtpwY8AYB8Q0yyYAuAoJsjDAlHd52vbjJqmtUcRyjJW72dBFCNgRdnp9cFajLHVxxUBFxuoUcQIZZlThpj8hCm4ev0Wn/jY+dRdHj/TULelj5P/oB+ot2m/FpKJsIeaRCVwVfyoHABFqrFBVdCYHEaaDFHNxak+d6s/XFQRjGo1vyd9ixdJ/kOMoSwCRRkwwHAoNBoZg8GQ5cUuN9c2pwD4aAIcBcBB4Q9jguw7lgkY05Gj2veKoibNAA1lICqosemjElXqSQmiqY9fT20UFYxYSgKZ9bgMrHVIyMmLnEYjg2aD/rAgRDP5XJWHB6BOVsbbGoDxtf15/cMnTxOQvJIGRRClKAucb4yHxmX8gUEaxJQYMd5VnwrZasJxlVFVLa8ylBifQmWMwl5/SBCDyD8GAPYDcUiTc/r44PV9YfJAyPT1B9PRRNTAIwtd+sOCwXCUJk7qJH5nmUcANeCMQysnmAZP0syvKAFrPRIFcUKvN+CpJ87w5rsfTglc5wHHAaBTx/rAduIkj2YBHHK+9gcTJ5g0akwqYePUZ67pK670yZRRQSTR3KtHbT1YOunzZ95iKntTk6hW5IGZTguR8JHaP4oF9ZQO3Xf9gC84xCQSSMebxv8HYGmsbAfuk/oAAAAASUVORK5CYII=

没有数据库条目时可以正常工作,但是当有数据库条目时,它会拒绝读取。

它创建的临时图像为空白

1 个答案:

答案 0 :(得分:1)

你的代码没有多大意义。看看其中一些问题 - 可以解决您的问题:

if ($row['date'] > $row['date']+100)将始终为false - 没有数字大于相同数字+100。

在您的while循环中,您正在访问$row['date']$row['avatar'],但未在SQL查询中选择dateavatar。仅存在$row['name']。这可能是您的空临时图像的原因。

您在while循环中使用$result['XboxInfo']['TileUrl'] - $result是一种资源,无法作为数组进行访问。我不知道你在这里要做什么。

在你正在使用$result['XboxInfo']['TileUrl']的else子句中,$result甚至没有定义。

您的UPDATE查询错误 - 更新多个值的语法是SET x = 1, y = 2而不是SET x = 1 SET y = 2 - 添加逗号并删除额外的SET。

祝你好运!