diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index c11cc37..5737ef7 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -298,7 +298,12 @@ class Curl $this->fileHandle = fopen($download_filename, $mode); // Move the downloaded temporary file to the destination save path. - $this->downloadCompleteFunction = function ($fh) use ($download_filename, $filename) { + $this->downloadCompleteFunction = function ($instance, $fh) use ($download_filename, $filename) { + // Close the open file handle before renaming the file. + if (is_resource($fh)) { + fclose($fh); + } + rename($download_filename, $filename); }; }