Skip to content

Commit

Permalink
Fix behaviour for empty external responses
Browse files Browse the repository at this point in the history
The file_put_contents function will return 0 if empty content is written, but this should not trigger a writing exception. Empty content should throw an exception before, when checking the curl response.

Fixes symphonycms#164
  • Loading branch information
michael-e committed Feb 28, 2019
1 parent 829183f commit d19c4df
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/class.image.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function loadExternal($uri){
// get the raw body response, ignore errors
$response = @$gateway->exec();

if($response === false){
if(!$response){
throw new Exception(sprintf('Error reading external image <code>%s</code>. Please check the URI.', $uri));
}

Expand All @@ -67,7 +67,7 @@ public static function loadExternal($uri){
// Symphony 2.4 enhances the TMP constant so it can be relied upon
$dest = tempnam(TMP, 'IMAGE');

if(!file_put_contents($dest, $response)) {
if(file_put_contents($dest, $response) === false) {
throw new Exception(sprintf('Error writing to temporary file <code>%s</code>.', $dest));
}

Expand Down

0 comments on commit d19c4df

Please sign in to comment.