0

Hello Guyz,

I wish that the Title of the thread explains itself a lot.

I would like to Save an image from an HTTP URL which actually redirects to another URL.

Actually, I am trying to Save the Profile picture of Facebook.

Example : https://graph.facebook.com/thakurbhai/picture

Now when you will open the link, it will redirect to another URL/jpeg image, which I would like to save.

I've tested my Code with normal image url (.jpg) and it works fine for that. But for redirecting URL, it saves a file example.jpg with size 0 bytes.

Help please !

1
Contributor
1
Reply
3
Views
5 Years
Discussion Span
Last Post by AnkurThakur
0

Nevermind ! I resolved it !

What I did :

1. Get the Headers of the URL.
2. Filter the Headers and look for Location header.
3. Now Use it ;)

<?php
$url = 'https://graph.facebook.com/thakurbhai/picture';

$location = get_headers($url, 1);

if (array_key_exists('Location', $location))
{
	echo $location['Location'];
}
?>

Remember: I am Getting Headers for a Secure URl, i.e, HTTPS (https://graph.facebook.com/thakurbhai/picture)
For doing that, you must have php_openssl enabled on your server.

Or you can do something like this :

<?php
if (extension_loaded('openssl'))
{

$url = 'https://graph.facebook.com/thakurbhai/picture';

$location = get_headers($url, 1);

if (array_key_exists('Location', $location))
{
	echo $location['Location'];
}

}
else
{
	echo "Sorry ! Open SSL Not enabled.";
}
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.