Category: >> PHP Code >> Saving Remote Images With PHP Bookmark and Share

<< lastnext >>

Snippet Name: Saving Remote Images With PHP

Description: Two ways to save remote images with PHP. The second way is useful if the allow_url_fopen function is disabled.

Also see:
» Simple image resize on mouseover
» Simple directory viewer / browser
» Resize and convert an image to a P...
» Convert text to image in php
» Read a web page directly in to a s...
» Analyze a remote image with PHP
» Recursive Directory Browser
» Include All Files In A Directory
» More File Type Detection in PHP
» Get Current Page URL
» Get Current Directory Name
» Measure script run time
» Random Image from Directory
» Text to GIF
» Write to File example
» Simple image scaling
» Show current time as PNG-image
» Check if an image exists (GD)
» Check if a file exists
» Gradient Image Generator
» Export table to Excel or MS Word f...
» Show basic image info
» Write text onto an image
» Storing images in a database
» Make grayscaled image
» Count lines in file
» Copy File From Server
» Remove All Files An A Given Direct...
» Simple CAPTCHA using the GD Image ...

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

// get a remote image and save it 
// $path example: '/home/www/images/myimage.jpg'
$remote_img = '';
$img = imagecreatefromjpeg($remote_img);
$path = 'images/';
imagejpeg($img, $path);
// Alternative Image Saving Using cURL - useful if 
// the allow_url_fopen function is disabled. 
// $fullpathexample: '/home/www/images/myimage.jpg'
function save_image($img, $fullpath){
	$ch = curl_init ($img);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
	curl_close ($ch);
	$fp = fopen($fullpath,'x');
	fwrite($fp, $rawdata);
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© | users online: 8