Skip to content

mikesmith-ge/instagram-media-downloader-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Instagram Media Downloader (PHP)

PHP Version License Maintenance

Lightweight PHP class to parse high-quality media URLs from public Instagram posts without API keys or external dependencies.

πŸ“‹ Overview

  • How to download Instagram photos in PHP
  • Get Instagram video URL programmatically

InstagramDownloader is a simple, open-source PHP tool that extracts media (images and videos) from public Instagram posts by parsing Open Graph meta tags. Perfect for educational purposes, prototypes, or small-scale projects.

Also available in: Python | PHP (you are here)

✨ Features

  • βœ… Zero dependencies – Pure PHP, no Composer packages required
  • πŸš€ Simple API – Single class with straightforward methods
  • πŸ–ΌοΈ Image & Video support – Extracts both image and video URLs
  • πŸ”’ Error handling – Validates URLs and handles network/parsing errors
  • 🎯 Public posts only – Works with any publicly accessible Instagram post
  • πŸ“¦ Namespace support – PSR-4 compatible (Instaboost\Tools)

πŸ“¦ Installation

Option 1: Direct Download

Download InstagramDownloader.php and include it in your project:

require_once 'path/to/InstagramDownloader.php';

use Instaboost\Tools\InstagramDownloader;

Option 2: Clone Repository

git clone https://github.com/mikesmith-ge/instagram-media-downloader-php.git
cd instagram-media-downloader-php

πŸš€ Usage

Basic Example

<?php

require_once 'InstagramDownloader.php';

use Instaboost\Tools\InstagramDownloader;

$downloader = new InstagramDownloader();

try {
    // Download media from a public Instagram post
    $media = $downloader->download('https://www.instagram.com/p/ABC123/');
    
    // Check media type
    if ($media['type'] === 'image') {
        echo "Image URL: " . $media['url'] . "\n";
    } elseif ($media['type'] === 'video') {
        echo "Video URL: " . $media['url'] . "\n";
        echo "Thumbnail: " . $media['thumbnail'] . "\n";
    }
    
} catch (Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}

Advanced Example: Downloading Multiple Posts

<?php

require_once 'InstagramDownloader.php';

use Instaboost\Tools\InstagramDownloader;

$urls = [
    'https://www.instagram.com/p/ABC123/',
    'https://www.instagram.com/reel/XYZ789/',
    'https://www.instagram.com/tv/DEF456/',
];

$downloader = new InstagramDownloader();

foreach ($urls as $url) {
    try {
        $media = $downloader->getMediaInfo($url);
        echo "βœ“ {$media['type']}: {$media['url']}\n";
    } catch (Exception $e) {
        echo "βœ— Error for {$url}: {$e->getMessage()}\n";
    }
    
    // Be nice to Instagram - add delay between requests
    sleep(2);
}

Response Format

// For images:
[
    'type' => 'image',
    'url' => 'https://scontent.cdninstagram.com/...'
]

// For videos:
[
    'type' => 'video',
    'url' => 'https://scontent.cdninstagram.com/...',
    'thumbnail' => 'https://scontent.cdninstagram.com/...'
]

βš™οΈ Requirements

  • PHP 7.4 or higher
  • cURL extension enabled
  • OpenSSL for HTTPS requests

⚠️ Limitations

This is a basic scraper with several important limitations:

  • ❌ Public posts only – Cannot access private accounts or stories
  • ⏱️ Rate limits – Instagram may block frequent requests from the same IP
  • 🚫 No authentication – Cannot bypass login walls or access restricted content
  • πŸ“‰ Fragile – Changes to Instagram's HTML structure may break functionality
  • 🎠 Single media only – Multi-image carousels will only return the first image
  • πŸ“Š No metadata – Cannot extract captions, likes, comments, or user information

πŸš€ Need More?

For production use cases, bypassing rate limits, accessing stories, private content, or building commercial applications, we recommend using a professional API solution:

πŸ‘‰ Instaboost API – Enterprise-grade Instagram data API with:

  • βœ… Unlimited rate limits
  • βœ… Stories, Reels, and IGTV support
  • βœ… Private account access (with authorization)
  • βœ… Full metadata extraction
  • βœ… Multi-image carousel support
  • βœ… 99.9% uptime SLA
  • βœ… Dedicated support

Learn more β†’

πŸ”„ Related Projects

Looking for other implementations?

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

⚑ Disclaimer

This tool is for educational purposes only. Scraping Instagram may violate their Terms of Service. Use responsibly and at your own risk. For commercial or production use, always use official APIs or authorized services.

πŸ“§ Support


Made with ❀️ by the Instaboost Team

About

Lightweight PHP class to extract high-quality images & videos from public Instagram posts. No API key required. Zero dependencies.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages