diff --git a/src/Faker/Provider/Image.php b/src/Faker/Provider/Image.php index 0e31d50fae..2f0aa30bce 100644 --- a/src/Faker/Provider/Image.php +++ b/src/Faker/Provider/Image.php @@ -74,9 +74,15 @@ public static function image($dir = null, $width = 640, $height = 480, $category $fp = fopen($filepath, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); - $success = curl_exec($ch); + $success = curl_exec($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200; + + if ($success) { + fclose($fp); + } else { + unlink($filepath); + } + curl_close($ch); - fclose($fp); } elseif (ini_get('allow_url_fopen')) { // use remote fopen() via copy() $success = copy($url, $filepath);