Advertisement
Guest User

Untitled

a guest
Aug 17th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.14 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. </head>
  6. <body>
  7. <?php
  8.  
  9. $TMPdir="/tmp/upload";
  10. $TMPfile="uploaded.tgz";
  11. $s="&#160;";
  12. $_SELF=$_SERVER['PHP_SELF'];
  13. $UploadedFile = isset($_FILES["uploadfile"]) ? $_FILES["uploadfile"] : "";
  14.  
  15. echo "<form enctype='multipart/form-data' action='".htmlspecialchars($_SELF)."' method='POST'>\n";
  16. echo "<b class='tab'>Datei:</b> <input name='uploadfile' type='file' size='50' maxlength='100000'>\n";
  17. echo "$s$s<input type='submit' value='Upload'><br/><br/>\n";
  18. echo "</form>\n";
  19.  
  20. if (!empty($UploadedFile)){
  21.     if (!is_dir("$TMPdir") AND !mkdir("$TMPdir",0777,true)) {
  22.         echo "<b class='tabred'>Error creating temp dir $TMPdir</b><br/>\n";
  23.     } else {
  24.         exec("rm -rf ".$TMPdir."/* 2>/dev/null",$output,$return_var);
  25.         if (!move_uploaded_file($UploadedFile['tmp_name'],"$TMPdir/$TMPfile")) {
  26.             echo "<b class='tabred'>Beim Upload trat ein Fehler auf, bitte noch mal probieren!</b><br/>\n";
  27.         } else {
  28.             $FileName = $UploadedFile['name'];
  29.             $FileSize = get_size($UploadedFile['size']);
  30.             $FileType = $UploadedFile['type'];
  31.             echo "<b class='tabgreen'>Die Datei</b> <b class='tab'>".$FileName."</b> <b class='tabgreen'>wurde erfolgreich hochgeladen</b> <b class='tab'>(".$FileSize.")</b><br/>\n";
  32.         }
  33.         exec("cd ".$TMPdir." && tar -xz --file=".$TMPfile."",$output,$return_var);
  34.         if ($return_var == "127") { echo "<p/><b>ERROR no such Script!</b><br/>\n"; $WORKS=0; }
  35.         elseif (!empty($output)) { echo "<br/>\n"; foreach ($output as $value) { echo "<b class=tab>".$value."</b><br/>\n"; } }
  36.         else { $WORKS=1; }
  37.         if ($WORKS === 0) {
  38.             echo "<br/><b>ERROR executing script!</b><br/>\n";
  39.         } else {
  40.             exec("cd ".$TMPdir."; rm -f ".$TMPfile."");
  41.             $EF0 = glob("$TMPdir/*");
  42.             if (!empty($EF0)) {
  43.                 $EF1 = glob("$TMPdir/*/*");
  44.                 $EF2 = glob("$TMPdir/*/*/*");
  45.                 $EF3 = glob("$TMPdir/*/*/*/*");
  46.                 $ExtractedFiles = array_merge($EF0,$EF1,$EF2,$EF3);
  47.                 foreach ($ExtractedFiles AS $File) {
  48.                     if (is_dir($File)) {
  49.                         echo "[dir] $s$s".substr("$File",12)."<br/>\n";
  50.                     } else {
  51.                         echo "[file] $s$s".substr("$File",12)."<br/>\n";
  52.                     }
  53.                 }
  54.                
  55.                 ## ... weitere aktionen mit den Dateien...
  56.                
  57.             } else { echo "<b class='tabred'>Es wurden keine Dateien entpackt!</b>\n"; }
  58.         }
  59.     }
  60. }
  61.  
  62.  
  63. function get_size($size,$precision=2,$long_name=true,$real_size=true) {
  64.    $base=$real_size?1024:1000;
  65.    $pos=0;
  66.    while ($size>$base) {
  67.       $size/=$base;
  68.       $pos++;
  69.    }
  70.    $prefix=get_size_prefix($pos);
  71.    $size_name=$long_name?$prefix."bytes":$prefix[0].'B';
  72.    return round($size,$precision).' '.ucfirst($size_name);
  73. }
  74.  
  75. function get_size_prefix($pos) {
  76.    switch ($pos) {
  77.       case 00: return "";
  78.       case 01: return "Kilo";
  79.       case 02: return "Mega";
  80.       case 03: return "Giga";
  81.       case 04: return "Tera";
  82.       case 05: return "Peta";
  83.       case 06: return "Exa";
  84.       case 07: return "Zetta";
  85.       case 08: return "Yotta";
  86.       case 09: return "Xenna";
  87.       case 10: return "W-";
  88.       case 11: return "Vendeka";
  89.       case 12: return "u-";
  90.       default: return "?-";
  91.    }
  92. }
  93.  
  94. ?>
  95.  
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement