You are here

public static function MigrateFileUri::urlencode in Migrate 7.2

Urlencode all the components of a remote filename.

Parameters

$filename:

Return value

string

1 call to MigrateFileUri::urlencode()
MigrateFileUri::copyFile in plugins/destinations/file.inc
Implementation of MigrateFile::copyFile().

File

plugins/destinations/file.inc, line 429
Support for file entity as destination. Note that File Fields have their own destination in fields.inc

Class

MigrateFileUri
Handle cases where we're handed a URI, or local filespec, representing a file to be imported to Drupal.

Code

public static function urlencode($filename) {

  // Only apply to a full URL
  if (strpos($filename, '://')) {
    $components = explode('/', $filename);
    foreach ($components as $key => $component) {
      $components[$key] = rawurlencode($component);
    }
    $filename = implode('/', $components);

    // Actually, we don't want certain characters encoded
    $filename = str_replace('%3A', ':', $filename);
    $filename = str_replace('%3F', '?', $filename);
    $filename = str_replace('%26', '&', $filename);
    $filename = str_replace('%40', '@', $filename);
  }
  return $filename;
}