You are here

public function MediaInternetFileHandler::preSave in D7 Media 7

Same name and namespace in other branches
  1. 7.4 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::preSave()
  2. 7.2 modules/media_internet/includes/MediaInternetFileHandler.inc \MediaInternetFileHandler::preSave()
  3. 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, media_variable_get('file_extensions'), 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);
}