How to return the absolute url
I've been trying to insert an image inside a php generated image (using imagecreatefromX() where x = gif, jpeg, or png) using a GET perimeter as the source url. I try to have it check what MIME type it is, by doing this:
$pic = $_GET['pic'];
switch(returnMIMEType($pic)) {
case "image/gif":
$profileImage = @imagecreatefromgif($pic) or die('Unable to load gif image.');
break;
case "image/jpg":
$profileImage = @imagecreatefromjpeg($pic) or die('Unable to load jpeg image.');
break;
case "image/png":
$profileImage = @imagecreatefrompng($pic) or die('Unable to load png image.');
break;
default:
$pic = 'http://www.example.com/image.gif';
$profileImage = @imagecreatefromgif($pic) or die('Unable to load gif image.');
break; 开发者_Python百科
}
$profileImageWidth = imagesx($profileImage);
$profileImageHeight = imagesy($profileImage);
imagecopyresized($image, $profileImage, 0, 0, 0, 0, 25, 25, $profileImageWidth, $profileImageHeight);
returnMIMEType() is just a simple function I came up with to return the MIME type.
When a url is given in this format: "http://graph.facebook.com/123456789/picture", it should return with a jpg image of the users profile picture on Facebook, but I'm assuming, and which is what I'm having issues with, is PHP is looking at that exact URL and not the url "http://graph.facebook.com/123456789/picture" redirects too. How would I have it so it understands to wait until the redirect?
Thank you for your consideration in this matter!
Here is the error it gives:
Warning: mime_content_type() [function.mime-content-type]: File or path not found
'http://graph.facebook.com/123456789/picture'
The redirect should not be an issue. Chances are, you have the ini setting allow_url_fopen set to false, so you are not allowed to open urls with file functions, and the error is being suppressed because you are using @
. Try double checking that you have enabled allow_url_fopen
, and if that doesn't work, try removing the @
for a more meaningful error message.
I tried using the http://graph.facebook.com/123456789/picture url and `imagecreatefromgif(), and it worked just fine for me.
EDIT: fileinfo functions do not like URLs. Try the following to the the mime type:
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_buffer($finfo, file_get_contents($url));
精彩评论