source: branches/1.2/workflow/inc/local/functions/function.wf_handle_download.php @ 1349

Revision 1349, 1.9 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * Handles download requests based on logic provided by the callback function.
4 * @param array $request Information about HTTP request
5 * @param string $callback Function that provides the logic for the download process.
6 * @return void
7 * @license http://www.gnu.org/copyleft/gpl.html GPL
8 * @package Workflow
9 * @subpackage local
10 * @access public
11 */
12function wf_handle_download($request, $callback)
13{
14        /* check if it is in download mode */
15        if (!isset($request['download_mode']))
16                return;
17        else
18                if ($request['download_mode'] != "true")
19                        return;
20       
21        /* verify if the callback function exists and is callable */
22        if ((function_exists($callback)) && (is_callable($callback)))
23        {
24                /* prepare the parameters */
25                $params = array();
26                foreach ($request as $key => $value)
27                        $params[$key] = $value;
28               
29                /* call the callback function and await the result */
30                $fileResult = call_user_func($callback, $params);
31               
32                /* if everything is ok, then proceed with the download of the file */
33                if (!is_null($fileResult))
34                {
35                        if (isset($fileResult['filename']) && isset($fileResult['content']))
36                        {
37                                        if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']))
38                                        $UserBrowser = "Opera";
39                                elseif (ereg('MSIE ([0-9].[0-9]{1,2})', $_SERVER['HTTP_USER_AGENT']))
40                                        $UserBrowser = "IE";
41                                        else
42                                                $UserBrowser = '';
43                               
44                                $mime_type = ($UserBrowser == 'IE' || $UserBrowser == 'Opera') ? 'application/octetstream' : 'application/octet-stream';
45                                header("Pragma: public");
46                                header("Cache-Control: cache, must-revalidate");
47                                header("Content-Type: application/force-download");
48                                header("Content-Disposition: attachment; filename=\"" . $fileResult['filename'] . "\"");
49                                header('Pragma: no-cache');
50                                header("Expires: 0");
51                        header("Content-length: " . strlen($fileResult['content']));
52                        echo $fileResult['content'];
53                                die();
54                        }
55                }
56                else
57                        die();
58        }
59}
60?>
Note: See TracBrowser for help on using the repository browser.