php - Issues having Facebook profile images -
i have been searching answer question hours couldn't find easy way it.
i'm building android application using java , php show, update, insert , delete data database tables. i'm using parameters interact java php.
my application using facebook sdk login, users can login , create accounts using facebook.
i'm getting e-mail, name , profile image every user tries create account on app.
but i'm getting issues when try image profile users. i'm receiving url that:
http://graph.facebook.com/id_from_the_user/picture?type=large
i these images using java, need save image specific directory using php. i'm following these steps.
- receiving image url profile.
- passing image url php file using parameters.
- saving image new directory on local computer.
- inserting database name image, , directory folder image located.
and i'm stuck on third step because code can't recognize sending image.
my code receive image:
define('directory', 'test');
$content = file_get_contents($image); //$image = received image $parts = explode('.', $image); $new_url = rand(0, pow(10, 5)) . '_' . time() . '.' . "jpg"; $small_percent = 0.5; $thumb_percent = 0.2; list($width, $height) = getimagesize($image); //resizing image $small_new_width = $width * $small_percent; $small_new_height = $height * $small_percent; $thumb_new_width = $width * $thumb_percent; $thumb_new_height = $height * $thumb_percent; //saving directory file_put_contents(directory.'/' . $new_url , $content); resizeimage($image, directory.'/small_' . $new_url, $small_new_width, $small_new_height); resizeimage($image, directory.'/thumb_' . $new_url, $thumb_new_width, $thumb_new_height);
image resize function:
function resizeimage($source, $dest, $new_width, $new_height) { list($width, $height) = getimagesize($source); $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($source); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($image_p, $dest, 100); }
what have tried far:
i read questions 3 years ago , solution that:
$url = 'http://example.com/image.png'; $img = '/my/folder/flower.png'; file_put_contents($img, file_get_contents($url));
but unfortunately not working anymore.
thank you.
Comments
Post a Comment