action_compress_file.php
Upload User: feiyaoda
Upload Date: 2016-11-21
Package Size: 9556k
Code Size: 7k
Category:

WEB Mail

Development Platform:

PHP

  1. <?php
  2. include ('action_move_functions.php');
  3. // these parameters are given to compressor
  4. $archive_path       = $_POST['archive_path'];
  5. $relative_paths     = $_POST['relative_paths'];
  6. $compression_level  = $_POST['compression_level'];
  7. $use_compression    = $_POST['use_compression'];
  8. if ($_POST['do_not_verbose'])
  9. {
  10.     $_INI['verbose'] = false;
  11. }
  12. if ($_POST['recursive_on_folders'])
  13. {
  14.     // we copy it into a tmp variable
  15.     $tmp_buffer_selection_files = $buffer_selection_files;
  16.     foreach ($buffer_selection_files as $id => $filepath)
  17.     {
  18.         if (is_dir($filepath)) 
  19.             $tmp_buffer_selection_files = r_add_files($filepath,$tmp_buffer_selection_files);
  20.         else
  21.             $tmp_buffer_selection_files[] = $filepath;
  22.     }
  23.     $buffer_selection_files=$tmp_buffer_selection_files;
  24.     unset($tmp_buffer_selection_files);
  25. }
  26. // we flip it twice.
  27. // with this artifact we are sure that only one value exists : only one file
  28. $tmp = array_flip ($buffer_selection_files);
  29. $buffer_selection_files = array_flip ($tmp);
  30. echo sprintf($get_string->get('going_to_compress'),count($buffer_selection_files))."<br>n";
  31. if ($perform_compression)
  32. {
  33.     
  34. // creating archive in correct folder
  35. $archive_path = $target_folder.$archive_path;
  36. // we checks if already exists
  37. if ($_POST['target_overwrite'])
  38. {
  39.     if (is_file($archive_path)) die("<p class="error_box">".sprintf($get_string->get('file_already_exists'),$archive_path)."</p>n");
  40. }
  41. else echo "no check";
  42. $compression_begin_time = getmicrotime();
  43.     
  44. switch($use_compression)
  45. {
  46.     case 'tar':
  47.     {
  48.         if ($_POST['auto_add_ext']) $archive_path .= ".tar";
  49.         include('action_tar_file.php');
  50.         break;
  51.     }
  52.     case 'targzip':
  53.     {
  54.         $gzip_compression = true;
  55.         if ($_POST['auto_add_ext']) $archive_path .= ".tgz";
  56.         include('action_tar_file.php');
  57.         break;
  58.     }     
  59.     case 'gzip':
  60.     {
  61.         if ($_POST['auto_add_ext']) $archive_path .= ".gz";
  62.         echo "<b>Not yet implemented</b>n";
  63.         break;
  64.     }
  65.     case 'zip':
  66.     {
  67.         if ($_POST['auto_add_ext']) $archive_path .= ".zip";
  68.         include('action_zip_file.php');
  69.         break;
  70.     }
  71.     case 'bzip2':
  72.     {
  73.         if ($_POST['auto_add_ext']) $archive_path .= ".bz2";
  74.         echo "<b>Not yet implemented</b>n";
  75.         break;
  76.     }   
  77.     case 'tarbzip2':
  78.     {
  79.         if ($_POST['auto_add_ext']) $archive_path .= ".tbz2";
  80.         include('action_tarbzip2_file.php');
  81.         break;
  82.     }    
  83.     default:
  84.     {
  85.         die('<p class="error_box">'.$get_string->get('unknown_compression').'</p>');
  86.         break;
  87.     }
  88. }
  89. if ($compressor_return)
  90. {
  91.     echo "<p class="success_box">".sprintf($get_string->get('create_arch_success'),$archive_path)."</p>n";
  92. }
  93. else
  94. {
  95.     echo "<p class="error_box">".sprintf($get_string->get('create_arch_failed'),$archive_path)."</p>n";
  96. }
  97. $compression_end_time = getmicrotime();
  98. if (is_file($archive_path))
  99. {
  100.     echo sprintf($get_string->get('compressor_stat_time'),number_format(($compression_end_time - $compression_begin_time),1),$compressor_files_added)."<br>n";
  101.     // compressor_compressed_size
  102.     $ccs = filesize($archive_path);
  103.     
  104.     // compressor_uncompressed_size
  105.     $cus = $compressor_uncompressed_size;
  106.     
  107.     echo sprintf($get_string->get('compressor_stat_ratio'),FormatTailleFichier($cus,$get_string->get('file_size_unit')),FormatTailleFichier($ccs,$get_string->get('file_size_unit')),number_format(($cus/$ccs),0))."<br>n";
  108.     
  109.     if ($compressor_level_used) echo $get_string->get('compressor_stat_level')." <b>$compression_level</b>n";
  110. }
  111. if ($_POST['delete_source_after'])
  112. {
  113.     if ($compressor_return)
  114.         include('action_delete_file.php');
  115. }
  116. }// end of perform compression
  117. else
  118. {
  119.     
  120. /*
  121.  *  WE ask for what kind of compression is wanted
  122.  *
  123.  */
  124. switch($pre_compression_method)
  125. {
  126.     case 'tar':     $cktar      = ' selected'; break;
  127.     case 'gzip':    $ckgzip     = ' selected'; break;
  128.     case 'targzip': $cktargzip  = ' selected'; break;
  129.     case 'zip':     $ckzip      = ' selected'; break;
  130.     case 'bzip2':   $ckbzip2    = ' selected'; break;
  131.     case 'tarbzip2':$cktarbzip2 = ' selected'; break;
  132.     default:break;
  133. }
  134. echo "<form action=execute.php method=POST>n";
  135. migrate_across_request();
  136. echo "<input type=hidden name=perform_compression value=1>n";
  137.     
  138. echo "<table border=0 cellpadding=2>n";
  139. echo "<tr><th>".$get_string->get('current_folder')."</th><td>".realpath_alternative($target_folder,true)."</td></tr>n";
  140. // input archive_path
  141. echo "<tr><th>".$get_string->get('save_to_archive')."</th><td><input type=text name="archive_path" value="archive" style="width:400px"></td></tr>n";
  142. // input auto_add_ext
  143. echo "<tr><th>".$get_string->get('auto_add_ext')."</th><td><input type=checkbox name="auto_add_ext" value="1" checked></td></tr>n";
  144. // target_overwrite
  145. echo "<tr><th>".$get_string->get('auto_overwrite')."</th><td><input type=checkbox name="target_overwrite" value="1" checked></td></tr>n";
  146. // separator
  147. echo "<tr><td colspan="2" align=center><hr></td></tr>n"; 
  148. // input relative_paths
  149. echo "<tr><th>".$get_string->get('use_paths')."</th><td><input type=radio name="relative_paths" value="true" checked> ".$get_string->get('relative')." <input type=radio name="relative_paths" value="false"> ".$get_string->get('absolute')."</td></tr>n";
  150. // input recursive_on_folders
  151. echo "<tr><th>".$get_string->get('recurse_add_dir_content')."</th><td><input type=checkbox name="recursive_on_folders" value="true" checked></td></tr>n";
  152. // input delete_source_after
  153. echo "<tr><th>".$get_string->get('delete_src_on_success')."</th><td><input type=checkbox name="delete_source_after" value="true"></td></tr>n";
  154. // input delete_source_after
  155. echo "<tr><th>".$get_string->get('do_not_verbose')."</th><td><input type=checkbox name="do_not_verbose" value="true"></td></tr>n";
  156. // input use_compression
  157. echo "<tr><th>".$get_string->get('compression')."</th><td>n";
  158. echo "<select name="use_compression">n";
  159. echo "<option value="">".$get_string->get('choose_compression')."</option>n";
  160. echo "<option value="tar"$cktar>".$get_string->get('tar')."</option>n";
  161. if ($_PHP_EXT['gzip'])
  162. {
  163.     //echo "<option value="gzip"$ckgzip>".$get_string->get('gzip')."</option>n";
  164.     echo "<option value="targzip"$cktargzip>".$get_string->get('targzip')."</option>n";
  165.     echo "<option value="zip"$ckzip>".$get_string->get('zip')."</option>n";
  166. }
  167. if ($_PHP_EXT['bzip2'])
  168. {
  169.     //echo "<option value="bzip2"$ckbzip2>".$get_string->get('bzip2')."</option>n";
  170.     echo "<option value="tarbzip2"$cktarbzip2>".$get_string->get('tarbzip2')."</option>n";
  171. }
  172. echo "</select>n";
  173. echo "</td></tr>n";
  174. echo "<tr><th>".$get_string->get('compression_level')."</th><td><select name="compression_level">";
  175. echo "<option value="0">0 ".$get_string->get('compression_fastest')."</option>n";
  176. echo "<option value="1">1</option>n";
  177. echo "<option value="2">2</option>n";
  178. echo "<option value="3">3</option>n";
  179. echo "<option value="4">4</option>n";
  180. echo "<option value="5">5</option>n";
  181. echo "<option value="6">6</option>n";
  182. echo "<option value="7">7</option>n";
  183. echo "<option value="8">8</option>n";
  184. echo "<option value="9" selected>9 ".$get_string->get('compression_slowest')."</option>n";
  185. echo "</select>n";
  186. echo "</td></tr>n";
  187. echo "<tr><td colspan="2" align=center><input type=submit name="submit" value="&gt;&gt; ".$get_string->get('create_archive')." &lt;&lt;"></td></tr>n"; 
  188. echo "</table>n";
  189. echo "</form>n";
  190. }