Reputation: 49
I am loading an image from a remote server (google for example), but PHP never treats it as an image. This is my code:
$photo = imagecreatefromstring(file_get_contents("https://some.com/image.jpg"));
$filename = $photo["name"];
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); //returns ""
$filepath = $photo["tmp_name"];
is_array(getimagesize($filepath); //returns false
What am I doing wrong?
Upvotes: 0
Views: 34
Reputation: 1413
imagecreatefromstring returns an image not array.
$photo = imagecreatefromstring(file_get_contents("https://some.com/image.jpg"));
ob_end_clean();
header('Content-type: image/jpeg');
imagejpeg($photo, null, 80);
If this code doesn't produce an image then start debugging from finding out the return value of file_get_contents().
Also - after creating an image (using any of imagecreatefrom... functions) you are dealing with image resource, not file system or any other object. Image resource does not have information you are trying to extract (name, pathinfo etc.)
Upvotes: 1