GD PHP Base64 Picture (png) error
- by hogofwar
This is part of my code:
$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')");
}
It comes up with multiple errors but I feel this one should be addressed first as the other could just be caused by the first error:
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
It also does create an entry in my mysql DB