function GrabImage($url, $filename = '') { if ($url == ''): return false; endif; if ($filename == '') { $ext = strrchr($url, '.'); if ($ext != '.gif' && $ext != '.jpg'): return false; endif; $filename = date('His') . $ext; } ob_start(); readfile($url); $img = ob_get_contents(); ob_end_clean(); $size = strlen($img); $fp2 = @fopen($filename, 'a'); fwrite($fp2, $img); fclose($fp2); return $filename; } $img = GrabImage('http://www.ipaye.cn/w/uploads/358897.jpg', ''); if ($img) { echo '<pre><img src=' . $img . '></pre>'; } else { echo 'false'; }