Skip to content
Advertisement

How to validate dimensions and format of an image URL in PHP?

My system does not host images on my server, I am using the one APIfrom imgurso it is only valid that the imput field where I insert the image URL is not empty:

JavaScript

But I need to validate that path of that image, which has minimum dimensions 400x400may be more but it cannot be less, image formats allowed png, jpe, svg,among others, this is in case another URLwrong path was added .

Image URL:

JavaScript

It is important that in the image validation only allow the URL to be from imgur

Javascript imgur ,,,,,

JavaScript

Advertisement

Answer

You can send the image directly from the client-side to the imgur API, via JS, or send to your PHP app server (server-side validation), which will validate and send the image to the imgur.

I recommend you using the server-side validation. In this case the image will be uploaded to your app server and get stored in a temporary directory, where you can access it with PHP, like this:

JavaScript

To get the image size with JS, just do the following before submitting the image:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement