I have been searching the answer for my question for hours but I couldn't find an easy way to do it.
I'm building an Android application using Java and PHP to show, update, insert and delete data from my Database tables. I'm using parameters to interact the Java with the PHP.
My application is using the Facebook sdk for the Login, the users can login and create their accounts using the facebook.
I'm getting the E-mail, name and profile image from every user that tries to create an account on my App.
But I'm getting some issues when I try to get the Image profile from the users. I'm receiving the URL like that:
http://graph.facebook.com/ID_FROM_THE_USER/picture?type=large
I could easily get these images only using Java, but I need to save the Image into a specific directory using PHP. I'm following these steps.
And I'm stuck on the third step because my code can't recognize that I am sending an Image.
My code to receive the 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 the 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 to my 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 I have tried by far:
I read some Questions from three years ago and the solution was that:
$url = 'http://example.com/image.png';
$img = '/my/folder/flower.png';
file_put_contents($img, file_get_contents($url));
But unfortunately is not working anymore.
Thank you.