PHP problems related to GetImageSize determining network Image types

Source: Internet
Author: User
PHP GetImageSize determining network Image types This post was last edited by ciscole at 2013-09-02$ data & nbsp ;=& nbsp; GetImageSize ($ logoUrl); & nbsp; if & nbs PHP's question about how to determine the network Image type of GetImageSize
This post was last edited by ciscole at 14:39:26
$data = GetImageSize($logoUrl); 

if $data[2] =='1' {
$logo = ImageCreateFromGIF($logoUrl); 
}

else if $data[2] =='2' {
$logo = ImageCreateFromJPEG($logoUrl); 

else {
$logo = ImageCreateFromPNG($logoUrl); 


Is it wrong for me to write this? How should I write it! Learning php for two days
The problem I want to solve is as follows:
Is an image URL, the image URL format is roughly such a http://www.x.com/logo.php? XXXXXX (no extension)
This image may be jpg, gif, or png.
What should I do! Share:
------ Solution --------------------
This is correct, but not strict.
If it's not 1 or 2, is it png? Isn't it anything else?

Because you are processing network images, you need to access the same image twice in a very short gap, which can easily trigger the alert of anti-Leech.
In addition, the network is complex, and it cannot be said that both of them will succeed.
This is better written.
if($s = file_get_contents($logoUrl)) {
  $logo = imagecreatefromstring($s);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.