You are here

function video_upload_file_transfer in Video 5

Same name and namespace in other branches
  1. 6 types/video_upload/video_upload.module \video_upload_file_transfer()
  2. 6.2 types/video_upload/video_upload.module \video_upload_file_transfer()

Variation on Drupal's file_transfer() function. The only difference is that set_time_limit() is called to allow for large files.

This code comes from audio module

Parameters

$source File to transfer.:

$headers An array of http headers to send along with file.:

1 call to video_upload_file_transfer()
video_upload_v_download in types/video_upload/video_upload.module
Implements the hook_v_download

File

types/video_upload/video_upload.module, line 198
Enable Uploaded videos support for video module.

Code

function video_upload_file_transfer($source, $headers) {
  ob_end_clean();
  foreach ($headers as $header) {

    // To prevent HTTP header injection, we delete new lines that are
    // not followed by a space or a tab.
    // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
    $header = preg_replace('/\\r?\\n(?!\\t| )/', '', $header);
    header($header);
  }
  $source = file_create_path($source);

  // Transfer file in 1024 byte chunks to save memory usage.
  if ($fd = fopen($source, 'rb')) {
    if (!ini_get('safe_mode')) {
      set_time_limit(0);
    }
    while (!feof($fd)) {
      print fread($fd, 1024);
      ob_flush();
      flush();
    }
    fclose($fd);
  }
  else {
    drupal_not_found();
  }
  exit;
}