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 class="brush:php;toolbar:false"><img src="' . $img . '">'; else echo "下载失败。"; } ?>