I’m doing a script that takes the image from Twitter API, and return’s it on base64, but I have troubles because the file is on a remote server (Twitter). Here I show the code, the main problem is with the fread() and filesize(). I get this:
Warning: filesize() [function.filesize]: stat failed for http://a0.twimg.com/profile_images/...jpg in...
<?
mysql_connect...;
mysql_select_db...;
$autho_name = ...;
include '../twitter/LibTwitter.php';
$sql = mysql_query("SELECT * FROM `users` ORDER BY id DESC");
while($result = mysql_fetch_array($sql)) {
$userid = $result["userid"];
$busqueda = $twitter->usersShow($userid);
$username = $busqueda["screen_name"];
$img_src = str_replace("_normal.", "_reasonably_small.", $busqueda["profile_image_url"]);
$imgbinary = fread(fopen($img_src, "r"), filesize($img_src));
$img_str = base64_encode($imgbinary);
echo '<img src="data:image/jpg;base64,'.$img_str.'" />';
}
?>
I replaced personal data with … because of obvious reasons, no problem with that. Thanks!
Just use
file_get_contents()to fetch the image, then it’s a simple matter of: