Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1319 from eberkund/patch-1
Browse files Browse the repository at this point in the history
Fix "Resource temporarily unavailable"
  • Loading branch information
fzaninotto authored Oct 11, 2017
2 parents a71e081 + fb0f2f1 commit 62ee2d8
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/Faker/Provider/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,22 @@ public static function image($dir = null, $width = 640, $height = 480, $category
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$success = curl_exec($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200;
fclose($fp);
curl_close($ch);

if ($success) {
fclose($fp);
} else {
if (!$success) {
unlink($filepath);
}

curl_close($ch);
// could not contact the distant URL or HTTP error - fail silently.
return false;
}
} elseif (ini_get('allow_url_fopen')) {
// use remote fopen() via copy()
$success = copy($url, $filepath);
} else {
return new \RuntimeException('The image formatter downloads an image from a remote HTTP server. Therefore, it requires that PHP can request remote hosts, either via cURL or fopen()');
}

if (!$success) {
// could not contact the distant URL or HTTP error - fail silently.
return false;
}

return $fullPath ? $filepath : $filename;
}
}

0 comments on commit 62ee2d8

Please sign in to comment.