Instagram photo and Video Downloader Script in PHP

In this tutorial I am going to share Instagram photo and Video Downloader Script written in php. If you want to create online tool to download Instagram photos and videos like many other tool already provide instagram photo and video download facility because Instagram don’t allow directly photo downloading form their website, So people uses web scraping technique and just read the OG sharing properties to extract the Instagram photo and videos CDN URL and make downloadable without using instagram api.

How to download Instagram photo and video using PHP

Just download instagram photo video downloader class form github.
Script have following features.

  • Validates Instagram URL (domain validation, URL path validation).
  • Uses OG properties to detect the image and video URL.
  • Supports Instagram photos, videos, and Instagram TV videos
  • Verbose error reporting with proper exceptions.
  • Full unit tests
  • No dependencies other than PHP curl extension (which is most likely enabled by already)

After downloading the Instagram downloader class just include in main downloading page and and set the photo / video url which need to download. and the following script will extract the CDN path of the photo or video so that you could easily download instagram photo / video from directly from instagram CDN.

require_once 'src/InstagramDownload.php'
use Ayesh\InstagramDownload\InstagramDownload;
$url = '';
try {
  $client = new InstagramDownload($url);
  $url = $client->getDownloadUrl(); // Returns the download URL.
  $type = $client->getType(); // Returns "image" or "video" depending on the media type.
catch (\InvalidArgumentException $exception) {
   * \InvalidArgumentException exceptions will be thrown if there is a validation 
   * error in the URL. You might want to break the code flow and report the error 
   * to your form handler at this point.
  $error = $exception->getMessage();
catch (\RuntimeException $exception) {
   * \RuntimeException exceptions will be thrown if the URL could not be 
   * fetched, parsed, or a media could not be extracted from the URL. 
  $error = $exception->getMessage();

Don’t forget to Subscribe My Public Notebook for more useful free scripts, tutorials and articles.

This awesome script developed by Ayesh. Visit their official repository for more information and follow for future updates.

Posted in PHP