source: pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/download.php @ 858

Last change on this file since 858 was 858, checked in by quyenla, 10 years ago

download

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3
4class Download extends MX_Controller
5{
6
7        public function __construct() {
8                parent::__construct();
9                $user = $this->session->userdata ( 'userInfo' );
10                $this->vservices->setApiUrl($this->config->item('api_url'));
11                $this->vservices->setConnection($this->curl);
12                $this->vservices->setUserId($user['us_id']);
13        }
14       
15        public function getFile () {
16                $data=  $this->input->post('data');
17                $treeArray=  json_decode($data,TRUE);
18           
19                if ((count($treeArray)==1) && ($treeArray[0]['type']=='file'))
20                {
21                    $file=$treeArray[0];
22                    echo $file['name'];
23                    $file = file_get_contents($treeArray[0]['fileurl']); 
24                    $local_file="".$treeArray[0]['name'];
25                    file_put_contents($local_file, $file);
26                    $download_rate = 512;
27                    $download_file = $treeArray[0]['name'];
28                }
29                die();
30               
31               
32               
33               
34               
35               
36               
37               
38               
39               
40
41
42   // send headers
43
44    header('Cache-control: private');
45    header('Content-Type: application/octet-stream');
46    header('Content-Length: '.filesize($local_file));
47    header('Content-Disposition: filename='.$download_file);
48 
49   
50    // flush content
51    flush();
52 
53    // open file stream
54    $file = fopen($local_file, "r");
55 
56    while (!feof($file)) {
57 
58        // send the current file part to the browser
59        print fread($file, round($download_rate * 1024));
60 
61        // flush the content to the browser
62        flush();
63 
64        // sleep one second
65        sleep(1);
66    }
67 
68    // close file stream
69    fclose($file);
70   
71                exit;
72           
73        }
74       
75
76}
77
78/* End of file privatecontent.php */
79/* Location: ./application/modules/ajax/controllers/privatecontent.php */
Note: See TracBrowser for help on using the repository browser.