Changeset 864 for pro-violet-viettel
- Timestamp:
- Mar 31, 2015 2:54:28 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/www/deploy/20150304/application/modules/ajax/controllers/download.php
r863 r864 15 15 16 16 public function getFile() { 17 17 18 $user = $this->session->userdata('userInfo'); 18 19 $data = $this->input->post('data'); 19 20 $treeArray = json_decode($data, TRUE); 20 21 22 foreach ($treeArray as $idx=>$tree) { 23 $treeArray[$idx]['fileurl'] = $this->encodePath($treeArray[$idx]['fileurl']); 24 $treeArray[$idx]['name']= $this->convert_vi_to_en($treeArray[$idx]['name']); 25 if ($tree['type'] == 'file') { 26 $path = $folder . "/" . $tree['name']; 27 $filecontent = file_get_contents($tree['fileurl']); 28 file_put_contents($path, $filecontent); 29 } 30 if ($tree['type'] == 'directory') { 31 $childDirs = $this->aasort($tree['childDirs'], "id"); 32 foreach ($childDirs as $index => $dir) { 33 $treeArray[$idx]['childDirs'][$index]['fileurl'] = $this->encodePath($treeArray[$idx]['childDirs'][$index]['fileurl']); 34 $treeArray[$idx]['childDirs'][$index]['name']= $this->convert_vi_to_en($treeArray[$idx]['childDirs'][$index]['name']); 35 } 36 $childDirs = $this->aasort($tree['childFiles'], "id"); 37 foreach ($childDirs as $index => $dir) { 38 echo $dir['name']."<br />"; 39 $treeArray[$idx]['childDirs'][$index]['fileurl'] = $this->encodePath($treeArray[$idx]['childDirs'][$index]['fileurl']); 40 $treeArray[$idx]['childDirs'][$index]['name']= $this->convert_vi_to_en($treeArray[$idx]['childDirs'][$index]['name']); 41 } 42 43 } 44 45 } 46 die(); 21 47 if ((count($treeArray) == 1) && ($treeArray[0]['type'] == 'file')) { 48 22 49 $file = $treeArray[0]; 23 50 $local_file = "downloads/" . $file['name']; … … 26 53 file_put_contents($local_file, $filecontent); 27 54 } else { 28 $download_file =$user['username']."_".date("d-m-Y");55 $download_file = $user['username'] . "_" . date("d-m-Y"); 29 56 $folder = "downloads/" . $download_file; 30 57 mkdir($folder, 0777); 31 foreach ($treeArray as $tree) 32 { 33 if($tree['type']=='file') 34 { 35 $path=$folder."/".$tree['name']; 36 $filecontent = file_get_contents($file['fileurl']); 58 foreach ($treeArray as $idx=>$tree) { 59 60 if ($tree['type'] == 'file') { 61 $path = $folder . "/" . $tree['name']; 62 $filecontent = file_get_contents($tree['fileurl']); 37 63 file_put_contents($path, $filecontent); 38 64 } 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; 65 if ($tree['type'] == 'directory') { 66 mkdir($folder . "/" . $tree['name']); 67 $childDirs = $this->aasort($tree['childDirs'], "id"); 68 foreach ($childDirs as $index => $dir) { 69 70 if ($dir['parentID'] == $tree['id']) { 71 $path = $folder . "/" . $tree['name'] . "/" . $dir['name']; 72 mkdir($path, 0777); 73 $childDirs[$index]['path'] = $path; 74 } else { 75 foreach ($childDirs as $index2 => $dir2) { 76 if ($dir2['id'] == $dir['parentID']) { 77 $path = $childDirs[$index2]['path'] . "/" . $dir['name']; 78 mkdir($path, 0777); 79 $childDirs[$index]['path'] = $path; 61 80 } 62 81 } 63 64 82 } 65 83 } 66 84 $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 85 foreach ($childFiles as $index => $file) { 86 if ($file['parentID'] == $tree['id']) { 87 $path = $folder . "/" . $tree['name'] . "/" . $file['name']; 88 $file['fileurl'] = $this->encodePath($file['fileurl']); 73 89 $filecontent = file_get_contents($file['fileurl']); 74 90 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); 91 } else { 92 foreach ($childDirs as $index2 => $dir2) { 93 if ($dir2['id'] == $file['parentID']) { 94 $path = $childDirs[$index2]['path'] . "/" . $file['name']; 95 $filecontent = file_get_contents($file['fileurl']); 96 file_put_contents($path, $filecontent); 85 97 } 86 98 } … … 89 101 } 90 102 } 91 92 $command ="tar -C downloads -cvf ".$folder.".zip"." $download_file";93 103 104 $command = "tar -C downloads -cvf " . $folder . ".zip" . " $download_file"; 105 94 106 exec($command); 95 $local_file = $folder.".zip"; 96 $download_file = $download_file.".zip"; 97 98 107 $local_file = $folder . ".zip"; 108 $download_file = $download_file . ".zip"; 99 109 } 100 110 $mime = "application/octet-stream"; 111 if (get_mime_by_extension($local_file) != "") { 112 $mime = get_mime_by_extension($local_file); 113 } 101 114 header('Cache-control: private'); 102 header('Content-Type: application/zip');115 header('Content-Type: ' . $mime); 103 116 header('Content-Length: ' . filesize($local_file)); 104 header('Content-Disposition: filename=' . $download_file); 105 $download_rate = 512; 106 107 // flush content 117 header('Content-Disposition: attachment; filename=' . $download_file); 118 $download_rate = 2048; 108 119 flush(); 109 110 // open file stream111 120 $file = fopen($local_file, "r"); 112 121 113 122 while (!feof($file)) { 114 115 // send the current file part to the browser116 123 print fread($file, round($download_rate * 1024)); 117 118 // flush the content to the browser119 124 flush(); 120 121 // sleep one second122 125 sleep(1); 123 126 } 124 125 // close file stream126 127 fclose($file); 127 //unlink($local_file); 128 if (isset($folder)) 129 { 130 //exec("rm -fr $folder"); 128 unlink($local_file); 129 if (isset($folder)) { 130 exec("rm -fr $folder"); 131 131 } 132 132 exit; 133 133 } 134 134 135 p ublicfunction aasort($array, $key) {135 private function aasort($array, $key) { 136 136 $sorter = array(); 137 137 $ret = array(); … … 148 148 } 149 149 150 private function encodePath($path) { 151 $fileName = $path; 152 $fileNames = explode("/", $fileName); 153 $name = $fileNames[(count($fileNames) - 1)]; 154 $fileName = str_replace($name, "", $fileName) . str_replace("+", "%20", urlencode($name)); 155 return $fileName; 156 } 157 158 private function convert_vi_to_en($str) { 159 $str = preg_replace("/(à |á|ạ|ả|ã|â|ầ|ấ|áº|ẩ|ẫ|Ä|ằ|ắ|ặ|ẳ|ẵ)/", "a", $str); 160 $str = preg_replace("/(Ú|é|ẹ|ẻ|ẜ|ê|á»|ế|á»|á»|á» 161 )/", "e", $str); 162 $str = preg_replace("/(ì|Ã|á»|á»|Ä©)/", "i", $str); 163 $str = preg_replace("/(ò|ó|á»|á»|õ|ÃŽ|á»|á»|á»|á»|á»|Æ¡|á»|á»|ợ|á»|ỡ)/", "o", $str); 164 $str = preg_replace("/(ù|ú|ụ|á»§|Å©|ư|ừ|ứ|á»±|á»|ữ)/", "u", $str); 165 $str = preg_replace("/(ỳ|Ü|ỵ|á»·|ỹ)/", "y", $str); 166 $str = preg_replace("/(Ä)/", "d", $str); 167 $str = preg_replace("/(Ã|Ã|Ạ|Ả|Ã|Ã|Ẋ|Ẁ|Ậ|ẚ|Ẫ|Ä|Ằ|Ắ|Ặ|Ẳ|Ẏ)/", "A", $str); 168 $str = preg_replace("/(Ã|Ã|ẞ|Ẻ|Ẍ|Ã|á»|ẟ|á»|á»|á»)/", "E", $str); 169 $str = preg_replace("/(Ã|Ã|á»|á»|Äš)/", "I", $str); 170 $str = preg_replace("/(Ã|Ã|á»|á»|Ã|Ã|á»|á»|á»|á»|á»|Æ |á»|á»|Ợ|á»|á» )/", "O", $str); 171 $str = preg_replace("/(Ã|Ã|Ề|Ị|Åš|Ư|Ừ|Ớ|á»°|Ử|á»®)/", "U", $str); 172 $str = preg_replace("/(Ỳ|Ã|Ỏ|á»¶|Ở)/", "Y", $str); 173 $str = preg_replace("/(Ä)/", "D", $str); 174 //$str = str_replace(" ", "-", str_replace("&*#39;","",$str)); 175 $str= str_replace(" ", "_", $str); 176 return $str; 177 } 178 150 179 } 151 180
Note: See TracChangeset
for help on using the changeset viewer.