public function MediaInternetFileHandler::preSave in D7 Media 7.4
Same name and namespace in other branches
- 7 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::preSave()
- 7.2 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::preSave()
- 7.3 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::preSave()
Before the file has been saved, implementors may do additional operations.
Parameters
object $file_obj:
Overrides MediaInternetBaseHandler::preSave
File
- modules/
media_internet/ includes/ MediaInternetFileHandler.inc, line 15 - Definition of MediaInternetFileHandler.
Class
- MediaInternetFileHandler
- A class for managing the addition of Internet files.
Code
public function preSave(&$file_obj) {
// Coppies the remote file locally.
$remote_uri = $file_obj->uri;
//@TODO: we should follow redirection here an save the final filename, not just the basename.
$local_filename = basename($remote_uri);
$local_filename = file_munge_filename($local_filename, variable_get('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm'), FALSE);
$local_uri = file_stream_wrapper_uri_normalize('temporary://' . $local_filename);
if (!@copy($remote_uri, $local_uri)) {
throw new Exception('Unable to add file ' . $remote_uri);
return;
}
// Make the current fileObject point to the local_uri, not the remote one.
$file_obj = file_uri_to_object($local_uri);
}