图片下载源码
程序员文章站
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>