Changeset 862
- Timestamp:
- Mar 31, 2015 1:24:29 PM (10 years ago)
- Location:
- pro-violet-viettel/www/deploy/20150304
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/download.php
r858 r862 1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');1 <?php 2 2 3 if (!defined('BASEPATH')) 4 exit('No direct script access allowed'); 3 5 4 class Download extends MX_Controller 5 { 6 class Download extends MX_Controller { 6 7 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')) 8 public function __construct() { 9 parent::__construct(); 10 $user = $this->session->userdata('userInfo'); 11 $this->vservices->setApiUrl($this->config->item('api_url')); 12 $this->vservices->setConnection($this->curl); 13 $this->vservices->setUserId($user['us_id']); 14 } 15 16 public function getFile() { 17 $user = $this->session->userdata('userInfo'); 18 $data = $this->input->post('data'); 19 $treeArray = json_decode($data, TRUE); 20 21 if ((count($treeArray) == 1) && ($treeArray[0]['type'] == 'file')) { 22 $file = $treeArray[0]; 23 $local_file = "downloads/" . $file['name']; 24 $download_file = $file['name']; 25 $filecontent = file_get_contents($file['fileurl']); 26 file_put_contents($local_file, $filecontent); 27 } else { 28 $download_file=$user['username']."_".date("d-m-Y"); 29 $folder = "downloads/" . $download_file; 30 mkdir($folder, 0777); 31 foreach ($treeArray as $tree) 32 { 33 if($tree['type']=='file') 20 34 { 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']; 35 $path=$folder."/".$tree['name']; 36 $filecontent = file_get_contents($file['fileurl']); 37 file_put_contents($path, $filecontent); 28 38 } 29 die(); 30 31 32 33 34 35 36 37 38 39 39 if($tree['type']=='directory') 40 { 41 mkdir($folder."/".$tree['name']); 42 $childDirs = $this->aasort($tree['childDirs'],"id"); 43 foreach ($childDirs as $index=>$dir) 44 { 45 if($dir['parentID']==$tree['id']) 46 { 47 48 $path=$folder."/".$tree['name']."/".$dir['name']; 49 mkdir($path,0777); 50 $childDirs[$index]['path']=$path; 51 } 52 else 53 { 54 foreach ($childDirs as $index2=>$dir2) 55 { 56 if($dir2['id']==$dir['parentID']) 57 { 58 $path=$childDirs[$index2]['path']."/".$dir['name']; 59 mkdir($path,0777); 60 $childDirs[$index]['path']=$path; 61 } 62 } 63 64 } 65 } 66 $childFiles = $tree['childFiles']; 67 foreach ($childFiles as $index=>$file) 68 { 69 if ($file['parentID']==$tree['id']) 70 { 71 $path=$folder."/".$tree['name']."/".$file['name']; 72 73 $filecontent = file_get_contents($file['fileurl']); 74 file_put_contents($path, $filecontent); 75 } 76 else 77 { 78 foreach ($childDirs as $index2=>$dir2) 79 { 80 if($dir2['id']==$file['parentID']) 81 { 82 $path=$childDirs[$index2]['path']."/".$file['name']; 83 $filecontent = file_get_contents($file['fileurl']); 84 file_put_contents($path, $filecontent); 85 } 86 } 87 } 88 } 89 } 90 } 91 $local_file = $folder.".zip"; 92 $download_file = $download_file.".zip"; 93 exec("zip -r ".$folder.".zip"." $folder/*"); 94 95 } 40 96 97 header('Cache-control: private'); 98 header('Content-Type: application/zip'); 99 header('Content-Length: ' . filesize($local_file)); 100 header('Content-Disposition: filename=' . $download_file); 101 $download_rate = 512; 41 102 42 // send headers 103 // flush content 104 flush(); 43 105 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); 106 // open file stream 107 $file = fopen($local_file, "r"); 108 109 while (!feof($file)) { 110 111 // send the current file part to the browser 112 print fread($file, round($download_rate * 1024)); 113 114 // flush the content to the browser 115 flush(); 116 117 // sleep one second 118 sleep(1); 119 } 120 121 // close file stream 122 fclose($file); 123 124 exit; 66 125 } 67 68 // close file stream 69 fclose($file); 70 71 exit; 72 73 } 74 126 127 public function aasort($array, $key) { 128 $sorter = array(); 129 $ret = array(); 130 reset($array); 131 foreach ($array as $ii => $va) { 132 $sorter[$ii] = $va[$key]; 133 } 134 asort($sorter); 135 foreach ($sorter as $ii => $va) { 136 $ret[$ii] = $array[$ii]; 137 } 138 $array = $ret; 139 return $array; 140 } 75 141 76 142 } -
pro-violet-viettel/www/deploy/20150304/assets/js/manager.js
r860 r862 424 424 } 425 425 426 var postdata = { 427 data: JSON.stringify(items) 428 }; 426 for (var i = 0; i < items.length; i++) { 427 if (items[i].type == 'directory') { 428 items[i] = self.getAllDirChilds(items[i]); 429 } 430 } 429 431 var url = o.host + "download/getFile/"; 430 432 self.redirectPost(url, { … … 1269 1271 var form = ''; 1270 1272 $.each(args, function (key, value) { 1271 alert (value);1273 1272 1274 form += "<input type='hidden' name='" 1273 1275 + key + "' value='" + value
Note: See TracChangeset
for help on using the changeset viewer.