Exemple #1
0
 /**
  * @param callable $pre
  * @param callable $content
  * @param callable $post
  * @return callable
  */
 function call_safe_dg($pre, $content, $post)
 {
     return function () use($pre, $content, $post) {
         return call_safe($pre, $content, $post);
     };
 }
Exemple #2
0
 /**
  * @param string|array $content
  * @param string $basename
  * @param string|finfo|null $mime
  * @todo http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
  */
 function http_response_file_download($content, $basename, $mime = null)
 {
     if (is_array($content)) {
         list($content, $length) = $content;
     } else {
         debug_enforce_type($content, 'string');
         $length = strlen($content);
     }
     if (null === $mime && class_exists('finfo')) {
         $mime = new finfo();
     }
     if (is_object($mime) && $mime instanceof finfo) {
         $mime = $mime->buffer($content, FILEINFO_MIME);
     }
     $headers = ['Pragma: public', 'Expires: -1', 'Cache-Control: public, must-revalidate, post-check=0, pre-check=0', "Content-Disposition: attachment; filename=\"{$basename}\"", "Content-Type: {$mime}", "Content-Length: {$length}"];
     http_output_compression(false);
     array_each($headers, header_dg());
     $download = function () use($content) {
         print $content;
         ob_flush();
         flush();
     };
     call_safe(max_execution_time_set_dg(0), $download, max_execution_time_set_dg(tuple_get(0)));
 }