Lightweight PHP class to parse high-quality media URLs from public Instagram posts without API keys or external dependencies.
- 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)
- β 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)
Download InstagramDownloader.php and include it in your project:
require_once 'path/to/InstagramDownloader.php';
use Instaboost\Tools\InstagramDownloader;git clone https://github.com/mikesmith-ge/instagram-media-downloader-php.git
cd instagram-media-downloader-php<?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";
}<?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);
}// For images:
[
'type' => 'image',
'url' => 'https://scontent.cdninstagram.com/...'
]
// For videos:
[
'type' => 'video',
'url' => 'https://scontent.cdninstagram.com/...',
'thumbnail' => 'https://scontent.cdninstagram.com/...'
]- PHP 7.4 or higher
- cURL extension enabled
- OpenSSL for HTTPS requests
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
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
Looking for other implementations?
- Python Version β Same functionality in Python
- TikTok Downloader (PHP) β Extract TikTok videos
- TikTok Downloader (Node.js) β TikTok downloader in JavaScript
- YouTube Shorts Downloader (Python) β Download YouTube Shorts
- YouTube Shorts Downloader (PHP) β YouTube in PHP
- YouTube Shorts Downloader (Node.js) β YouTube in JavaScript
- More tools coming soon!
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
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.
- π Found a bug? Open an issue
- π‘ Have a suggestion? Start a discussion
- π Need enterprise features? Visit Instaboost
Made with β€οΈ by the Instaboost Team