PHP 将任何网站图像保存到您的服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 将任何网站图像保存到您的服务器相关的知识,希望对你有一定的参考价值。

<?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');

?>

以上是关于PHP 将任何网站图像保存到您的服务器的主要内容,如果未能解决你的问题,请参考以下文章