Sometimes, when publishing content, We need to extract external images and store them on our servers. This can avoid affecting our website if the external images cannot be opened, now let's share the functions that Drupal implements this function. Sometimes, when publishing content, We need to extract external images and store them on our servers. This can avoid affecting our website if the external images cannot be opened, now let's share the functions that Drupal implements this function.
Script ec (2); script
In Drupal, an external link image is automatically obtained, and then extracted and uploaded to your website for function sharing.
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 ");