Home >php教程 >PHP源码 >图片下载源码

图片下载源码

PHP中文网
PHP中文网Original
2016-05-25 17:06:491510browse

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 "下载失败。"; } ?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn