Return to Snippet

Revision: 27852
at June 25, 2010 06:19 by Nettuts


Initial Code
<?php

function saveImage($path) {

	if ( !preg_match('/\/([^\/]+\.[a-z]{3,4})$/i', $path, $matches) ) die('Use image please');
	
	$image_name = strToLower($matches[1]);
	
	$ch = curl_init ($path);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);

	$img = curl_exec ($ch);
	curl_close ($ch);

	$fp = fopen($image_name,'w');
	fwrite($fp, $img); 
	fclose($fp);

}

saveImage('http://nettuts.s3.cdn.plus.org/513_jsFromNull/javascript-from-null.jpg');

?>

Initial URL

                                

Initial Description

                                

Initial Title
Save Any Website Image to your Server

Initial Tags
curl, php, images

Initial Language
PHP