Сохранить изображение на сервере param url return array public functio

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Сохранить изображение на сервере.
* @param $url
* @return array
*/
public function SaveImgFile($url)
{
$fl = new CFile;
$arFileImage = array();
if($url <> "")
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($retCode == 200)
{
$arFile = $fl->MakeFileArray($url, false, false);
$arFile['del'] = 'Y';
$arFile['type'] = '';
$arFile['old_file'] = '';
$arFile['MODULE_ID'] = 'iblock';
//file_put_contents($_SERVER["DOCUMENT_ROOT"]."/eventsend_log.txt", var_export($arFile, true), FILE_APPEND | LOCK_EX);
$fid = $fl->SaveFile($arFile, "iblock");
//echo $fid;
unset($arFile);
$rsFile = $fl->GetByID($fid);
$arFile = $rsFile->Fetch();
$arFileImage['ID'] = $arFile['ID'];
$arFileImage['SRC'] = '/upload/'.$arFile['SUBDIR'].'/'.$arFile['FILE_NAME'];
//echo "<pre>"; var_dump($arFileImage); echo "</pre>";
//die();
$rsImages = $fl->ResizeImageFile(
$sourceFile = $_SERVER['DOCUMENT_ROOT'].'/upload/'.$arFile['SUBDIR'].'/'.$arFile['FILE_NAME'],
$destinationFile = $_SERVER['DOCUMENT_ROOT'].'/upload/'.$arFile['SUBDIR'].'/images_new.png',
$arSize = array(),
$resizeType = BX_RESIZE_IMAGE_PROPORTIONAL_ALT,
$arWaterMark = array(),
$jpgQuality = 85,
$arFilters = false
);
if($rsImages)
{
unlink($_SERVER['DOCUMENT_ROOT'].'/upload/'.$arFile['SUBDIR'].'/'.$arFile['FILE_NAME']);
rename($_SERVER['DOCUMENT_ROOT'].'/upload/'.$arFile['SUBDIR'].'/images_new.png', $_SERVER['DOCUMENT_ROOT'].'/upload/'.$arFile['SUBDIR'].'/'.$arFile['FILE_NAME']);
}
//echo "<pre>"; var_dump( $rsImages ); echo "</pre>";
//$fl->Delete($arFileImage['ID']);
//die();
}
elseif($retCode >= 400)
{
$arFileImage = array('ID' => NO_PHOTO_ID, 'SRC' => itc\Resizer::get(NO_PHOTO_ID, 'crop', 320, 480, NO_PHOTO_EXTENSION));
}
curl_close($ch);
}
else
{
$arFileImage = array('ID' => NO_PHOTO_ID, 'SRC' => itc\Resizer::get(NO_PHOTO_ID, 'crop', 320, 480, NO_PHOTO_EXTENSION));
}
//echo "<pre>"; var_dump($arFileImage); echo "</pre>";
unset($fl, $ch, $arFile);
//echo "<pre>"; var_dump($arFileImage); echo "</pre>";
//die();
return $arFileImage;
}