$gravatar_id, "rating" => $rating, "size" => $size, "default" => $default, "border" => $border)); // XXX: // Could create this request manually, to enable sniffing of the HTTP Response code $handle = fopen($url, "r"); // The result of the URL Request, no headers $rawimage = ""; do { $data = fread($handle, 8192); if (strlen($data) == 0) { break; } $rawimage .= $data; } while (true); fclose($handle); // Base 64 encode the image, for storing in the database // Note: It should be possible to store the actual raw image in a "BLOB" field // but the original script didn't do this. $image = base64_encode($rawimage); $res = @mysql_query('REPLACE INTO `'.$mysql_table."` SET md5=MD5('".$gravatar_id."'), updated=NOW(), data='".$image."';") or doError("Query Failed"); } // I have no idea how to determine the mime type // But this seems to work for PNG/GIF/JPEG... for some reason // (Firefox 1.0) // XXX: // I can only think of constructing the HTTP request above manually. // This would mean I could sniff and store the Content-Type header from the HTTP // Response and store it in the database. header("Content-Type: image/jpeg"); print base64_decode($image); // Error Handler function doError($msg = "Bad Request") { header("Content-Type: text/plain"); print $msg; exit; } // Helper Function function create_link ($in) { $out = "?"; $i = 1; foreach ($in as $field => $val) { if ($field && $val) { if ($i) { $out .= "&"; } $out .= $field . "=" . urlencode($val); $i++; } } return $out; }