Download Instagram Photo Video using PHP

In this tutorial I am going to share simple PHP library to Download Instagram Photo Video using PHP. If you are working on project where you need to dynamically download Instagram photo by image url then this tutorial for you. Here we have shared awesome php library which will help you quickly download Instagram images just in click.

Step.1: Install the library by running the following in your project via composer method.

composer require ayesh/instagram-download

OR
Step.2:

Without composer
Download the zip file from Github, and configure your autoload handler to autoload PSR-4 Ayesh\InstagramDownload namespace from the downloaded contents src directory.

require_once 'src/InstagramDownload.php'


Step.3: Finally set the instagram photo url and download the image in your local here is the sample code.

<?php
use Ayesh\InstagramDownload\InstagramDownload;
$url = 'http://instagram.com/p/tmwAlCGygb/';
 
try {
  $client = new InstagramDownload($url);
  $url = $client->getDownloadUrl(); 
  $type = $client->getType(); // Returns "image" or "video" depending on the media type.
}
catch (\InvalidArgumentException $exception) {
  
  $error = $exception->getMessage();
}
catch (\RuntimeException $exception) {
  
  $error = $exception->getMessage();
}

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)

DEMO | DOWNLOAD

This awesome script written by Ayesh, Visit their official github repository and follow for
future updates.

Posted in PHP