Answer the question
In order to leave comments, you need to log in
How to transfer images to Bitrix using external links?
When editing the site, managers often copied information from partner sites and pasted it as is into the visual editor.
As a result, many photos ended up with paths to other external sites.
We need some solution to go through all the posts, find links to external images, download them in uploads for example and replace the paths.
Maybe someone faced a similar problem?
Answer the question
In order to leave comments, you need to log in
Solution, if the links are a detailed description of the elements of the infoblock, then
1) Get all the elements of CIBlockElement::GetList
2) Look for links in the block https://inverser.pro/123-poisk-i-zamena-ssylok-vnu... - here what can be found on the net as a regular expression
3) Load CFile::SaveFile
4) Change the link to the file
5) Update the infoblock element
If inside the infoblock, then we run GetList and
get regular links, something like this:
["'](((http[s]?:)?\/\/).*?\.(jp[e]?g|png|gif|tiff|bmp))['"]
// скачиваем файл
$file = CFile::MakeFileArray('http://bipbap.ru/wp-content/uploads/2017/10/0_8eb56_842bba74_XL-640x400.jpg');
// сохраняем в папку /uploads/saved/
$savedFileId = CFile::SaveFile($file, 'saved');
// получаем ссылку
$savedFileSrc = CFile::GetPath($savedFileId);
$savedFileSrc
new relative url , we Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question