Snippets

Alexey ilyaskin Download image function

You are viewing an old version of this snippet. View the current version.
Revised by Alexey ilyaskin 50ce10e
function downloadImage($source, $targetPath) {
	$imageFile = file_get_contents($source);
	$imageName = basename($source);
	// русские имена файлов
	$imageName = mb_convert_encoding($imageName,"windows-1251","UTF-8");
	$imageTarget = $targetPath . '/' . $imageName;
	file_put_contents($imageTarget, $imageFile);
	if (file_exists($imageTarget) && filesize($imageTarget) > 0) {
		return $imageTarget;
	}
	return false;
}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.