public function downloadFromUrl($path, $newFilePath = null)
{
$tmpFilePath = tempnam(sys_get_temp_dir(), 'dvs_downloaded_field');
try {
$ch = curl_init($path);
$fp = fopen($tmpFilePath, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
// add the extension to this temp file
// and rename to a md5 string so it is unique
// in case we download this file again
$ext = image_type_to_extension(exif_imagetype($tmpFilePath));
$md5 = md5_file($tmpFilePath);
$newFilePath = $newFilePath ?: sys_get_temp_dir() . '/' . $md5 . $ext;
rename($tmpFilePath, $newFilePath);
return $newFilePath;
} catch (\Exception $e) {
}
return $path;
}