1

I am dealing with images on the web that come without a file extension, like this:

https://static1.squarespace.com/static/52a74d9ae4b0253945d2aee9/t/52ed63b1e4b04368c021b921/1463088116168/?format=500w

Images like these can be found, e.g., on websites made with squarespace, like this demo: https://bedford-demo.squarespace.com/

I'm trying to download these images and store them on my server, using PHP. But how can I find out the actual URL of those images? How does this work? And how can I tell the filetype of this image? What is this sorcery?

Any hints are appreciated!

Sebastian
  • 831
  • 2
  • 13
  • 36

2 Answers2

3

Quick answer:

To find out the Content-Type returned for any URL, look at this answer:
Get Content-Type of requested URL in PHP


Why you need the Content-Type:

Just like how not every webpage on the internet has an URL that ends with .html, images are not required to have an "extension" in their URL either.

What determines whether the browser will treat the data retrieved from the URL as an image is the Content-Type header in the HTTP response.

The URL you posted returns the following HTTP headers:

enter image description here

For HTML documents the Content-Type is text/html. You can inspect the headers as you browse by opening the Network tab of the developer console in your browser. Look for the "response headers".

Mate Solymosi
  • 5,699
  • 23
  • 30
2

You can get the mime type of the file with getimagesize:

<?php
$size = getimagesize("https://static1.squarespace.com/static/52a74d9ae4b0253945d2aee9".
            "/t/52ed63b1e4b04368c021b921/1463088116168/?format=500w");
print_r($size["mime"]);
?>

Prints:

image/jpeg
Marvin
  • 13,325
  • 3
  • 51
  • 57