欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

图片下载源码

程序员文章站 2022-05-12 18:47:21
...
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 ['submit'] != NULL) {
	$img = GrabImage ( $_POST ['url'] );
	if ($img)
		echo '<pre><img src="' . $img . '"></pre>';
	else
		echo "下载失败。";
}
?>
</form>
</body>
</html>
相关标签: 图片下载