首页 >php教程 >PHP源码 >图片下载源码

图片下载源码

PHP中文网
PHP中文网原创
2016-05-25 17:06:491521浏览

php代码:

<?php
function GrabImage($url, $filename = "") {
	if ($url == "")
		return false;
	if ($filename == "") {
		$ext = strrchr ( $url, "." );
		if ($ext != ".gif" && $ext != ".jpg" && $ext != ".png" && $ext != ".bmp")
			return false;
		$filename = date ( "dMYHis" ) . $ext;
	}
	ob_start ();
	readfile ( $url );
	$img = ob_get_contents ();
	ob_end_clean ();
	$fp2 = @fopen ( $filename, "a" );
	fwrite ( $fp2, $img );
	fclose ( $fp2 );
	return $filename;
}
?>
<html>
<head>
<title>图片下载</title>
</head>
<body>
	<form method="POST" action="index.php">
		图片URL: <input type="text" name="url" size="80" /> <input type="submit"
			name="submit" value="提交" /><br />
<?php
if ($_POST [&#39;submit&#39;] != NULL) {
	$img = GrabImage ( $_POST [&#39;url&#39;] );
	if ($img)
		echo &#39;<pre class="brush:php;toolbar:false"><img src="&#39; . $img . &#39;">
'; else echo "下载失败。"; } ?>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn