Search code examples
phpregeximage-uploadingparse-url

Check whether remote URL has a valid image extension


How can I check that a remote URL has a valid image extension?

What I want to do is upload images via link using PHP

copy('http://website.com/image.jpg', '/upload/filename.jpeg');

Code works fine but i want to check whether entered url has a valid image extension.

It should be jpg, png or gif file. Love to see a example of how to do this.

Your help and time is highly appreciated.


Solution

  • I found the solution myself.

    exif_imagetype($image_url);
    

    which will output the mime type for validation.