Search
 
SCRIPT & CODE EXAMPLE
 

PHP

validate if correct image url php

If you want to be absolutely sure, and your PHP is enabled for remote 
connections, you can just use "getimagesize('url')"

function validImage($url) {
   return stripos(getimagesize($url)['mime'], 'image') === 0;
}

$image = validImage('http://www.example.com/image.jpg');

If it returns an array, it is an image type recognized by PHP, even if the 
image extension is not in the url (per your second link). You have to keep in
mind that this method will make a remote connection for each request, so 
perhaps cache urls that you already probed in a database to lower connections.
Comment

PREVIOUS NEXT
Code Example
Php :: convert object to array php 
Php :: current page link using php 
Php :: wp get post thumbnail 
Php :: laravel 5.4 forelse 
Php :: laravel scaffolding 
Php :: display nav menu in frontend using Wordpress 
Php :: make pagination wordpress admin panel 
Php :: laravel get path to storage folder 
Php :: php tags 
Php :: php 7.4 extension sqlite ubuntu 
Php :: Turning a StdClass object into an array 
Php :: laravel dusk run failed tests 
Php :: laravel subdays 
Php :: get image size php 
Php :: ci count 
Php :: curl php post 
Php :: checking php version 
Php :: link to another page php 
Php :: How to check leap year in php? 
Php :: php from 
Php :: laravel check collection has key 
Php :: wordpress get text of wordpress post 
Php :: php call protected function from child class 
Php :: array_map class method 
Php :: how to return 0 as true in laravel 
Php :: how to use dompdf in laravel 
Php :: laravel blade get authenticated user email 
Php :: php get extension from file from form submit 
Php :: symfony request get all parameters 
Php :: check string length is greater than 0 php 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =