Snippets

Alexey ilyaskin Download image function

Created by Alexey ilyaskin last modified
<?php
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;
}

Comments (0)

HTTPS SSH

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