{% else-1 %}
По просьбе одного товарища
примеры
copy_image_from_url(\'http://
koenig.h2m.ru....php?f=54\');
copy_image_from_url(\'http://annimon.com/
t...o_new.png\');
copy_image_from_url(\'http://koenig.h2m.ru/test/
img/sm/zvezdy.gif\');
copy_image_from_url(\'http://seclub.org/img/
touch-logo.png\');
copy_image_from_url(\'http://johncms.com/
theme/varg/images/logo.gif\');

                        
function copy_image_from_url($url) {
if (list(, , $type) = getimagesize($url)) {
$type_ext = array('ext' ,'gif', 'jpg', 'png', 'jpeg');
if (!$type) {
return false;
}
$dir = 'img'; // указать свою, желательно от
корня сервера
if (!is_dir($dir)) {
mkdir($dir);
}
$newfile = basename(rtrim($url, '/'));
$ext = mb_strtolower(end(explode('.', $newfile)));
if (!in_array($ext, $type_ext)) {
$newfile .= '.' . $type_ext[$type];
}
if (file_exists($dir . DIRECTORY_SEPARATOR .
$newfile)) {
$newfile .= '-' . time() . '.' . $type_ext[$type];
}
$uploadfil = new SplFileObject($url, 'rb');
$file = new SplFileObject($dir .
DIRECTORY_SEPARATOR . $newfile, 'w');
$file->setFlags(SplFileObject::SKIP_EMPTY);
if ($file->flock(LOCK_EX)) {
$file->ftruncate(0);
while (!$uploadfil->eof()) {
$file->fwrite($uploadfil->fgets());
}
}
$file->flock(LOCK_UN);
if (file_exists($dir . DIRECTORY_SEPARATOR .
$newfile)) {
return true;
}
} else {
return false;
}
}
0 24 0
Без комментариев...