A
A
Alexander Balya2019-04-14 20:00:43
1C-Bitrix
Alexander Balya, 2019-04-14 20:00:43

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

3 answer(s)
K
Kirill Proger, 2019-04-15
@freekirill

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

K
Kudis, 2019-04-15
@kudis

If inside the infoblock, then we run GetList and
get regular links, something like this:

["'](((http[s]?:)?\/\/).*?\.(jp[e]?g|png|gif|tiff|bmp))['"]

if the links are not complete, we get to http[s] and feed it to the script:
// скачиваем файл
$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);

here is the $savedFileSrcnew relative url , we
replace external links with it

D
DevMan, 2017-02-20
@game802

more or less like this:

SELECT
    *
FROM
    `dle_post`
JOIN
    `dle_post_extras` ON `dle_post_extras`.id = `dle_post`.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question