有时我们发布内容的时候,需要提取外部图片,并保存到自己服务器上,这样可以避免如果外部图片打不开时影响到自己的网站,现在我们来分享Drupal实现这个功能的函数。
在Drupal中自动获取外部链接图片,然后提取出来上传到自己网站的函数分享。
function get_external_image($url) {
$external_image = file_get_contents($url);
$parsed_url = parse_url($url);
$name_dest = rand(1000,9999)."_". basename($parsed_url["path"]);
$file = file_save_data($external_image, 'public://'.$name_dest , FILE_EXISTS_REPLACE);
if (is_object($file) && file_exists($file->uri)) {
$file->status = 1;
$file = file_save($file);
drupal_write_record('file_usage', $file);
return (array) $file;
}
return null;
}
get_external_image("http://www.drupalla.com/logo.gif");

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools