php 線上解壓程式

來源:互聯網
上載者:User

<?php教程

 代碼如下 複製代碼

HtmlHead("選擇解壓檔案:") ;

if ( !IsSet($HTTP_POST_VARS['submit']) )
{
 TestWriteable() ;
 $gzip_info = "" ;
 echo "check zlib support... " ;
 if ( !function_exists("gzopen") )
 {
  $gzip_info = "<font color="red">注意! 您的空間沒有zlib支援,因此用
  <a href="http://www.111cn.net/" target="_blank"><font color="blue">phpZip</font></a>
  壓縮檔時,不要選擇“壓縮成Gzip格式”,否則將無法正確解壓!</font>" ;
 }
 else
 {
  $gzip_info = "<font color="blue">恭喜! 您的空間支援zlib壓縮,強烈建議用
  <a href="http://www.111cn.net/"><font color="red" target="_blank">phpZip</font></a>
  壓縮檔時,選中“壓縮成Gzip格式”,將會大大減少檔案大小!</font>" ;
 }
 echo " ----------------- OK!<br> " . $gzip_info ;
 
 echo "<br><br><br><br>
<form action="{$_SERVER["PHP_SELF"]}" method="post" enctype="multipart/form-data">
<table align="center" width="450">
<tr><td height="20" colspan="2">請先選擇壓縮檔的位置,然後點擊“確定”按鈕: <p></td></tr>
<tr>
<td><input type="radio" name="file_type" value="upload" checked onclick="this.form.upload_file.disabled=false; this.form.server_filename.disabled=true">檔案從本地上傳: </td>
<td>
<input name="upload_file" type="file" style="color:#0000ff">
</td>
</tr>

<tr><td colspan=2 height=10></td></tr>

<tr>
<td><input type="radio" name="file_type" value="server" onclick="this.form.upload_file.disabled=true; this.form.server_filename.disabled=false">指定伺服器上檔案:</td>
<td><input name="server_filename" value="data.dat.gz" style="color:#0000ff" disabled >(可以用"."表示目前的目錄)</td>
</tr>

<tr><td colspan="2" align=center><br><input type="submit" name="submit" value="確定"></td></tr>
</table>
</form>
" ;
 HtmlFoot() ;
 exit ;
}

if ( $_POST['file_type'] == 'upload' )
{
 $tmpfile = $_FILES['upload_file']['tmp_name'] ;
}
else
{
 $tmpfile = $_POST['server_filename'] ;
}

if ( !$tmpfile )
{
 exit("無效的檔案或檔案不存在,可能原因有檔案大小太大,上傳失敗或沒有指定伺服器端檔案等") ; 
}

$bgzExist = FALSE ;
if ( function_exists("gzopen") )
{
 $bgzExist = TRUE ;
}

$alldata = "" ;
$pos = 0 ;

$gzp = $bgzExist ? @gzopen($tmpfile, "rb") : @fopen($tmpfile, "rb") ;
$szReaded = "has" ;
while ( $szReaded )
{
 $szReaded = $bgzExist ? @gzread($gzp, 2*1024*1024) : @fread($gzp, 2*1024*1024) ;
 $alldata .= $szReaded ;
}
$bgzExist ? @gzclose($gzp) : @fclose($gzp) ;

$nFileCount = substr($alldata, $pos, 16) ;
$pos += 16 ;

$size = substr($alldata, $pos, 16) ;
$pos += 16 ;

$info = substr($alldata, $pos, $size-1) ;  // strip the last ' '
$pos += $size ;

$info_array = explode(" ", $info) ;

$c_file = 0 ;
$c_dir = 0 ;

foreach ($info_array as $str_row)
{
 list($filename, $attr) = explode("|", $str_row);
 if ( substr($attr,0,6) == "[/dir]" )
 {
  echo "End of dir $filename<br>";
  continue;
 }
 
 if ( substr($attr,0,5)=="[dir]" )
 {
  if ( @mkdir($filename, 0777) )
   echo "Make dir $filename<br>";
  $c_dir++ ;
 }
 else
 {
  $fp = @fopen($filename, "wb") or exit("不能建立檔案 $filename ,因為沒有寫入權限,請修改許可權");
  @fwrite($fp, substr($alldata, $pos, $attr) );
  $pos += $attr ;
  fclose($fp);
  echo "Create file $filename<br>";
  $c_file++ ;
 }
}

if ( $_POST['file_type'] == 'upload' )
{
 if ( @unlink($tmpfile) ) echo "刪除臨時檔案 $tmpfile...<br>" ;
}

echo "<h1>操作完畢! 共解出檔案 $c_file 個, 檔案夾 $c_dir 個,謝謝使用!</h1><p>" ;
HtmlFoot() ;


function TestWriteable()
{
 $safemode = '
建立一檔案,命名為 unzip2.php (或其它名字), 其內容如下:

<?php
copy("unzip.php", "unzip_safe.php") ;
header("location:unzip_safe.php") ;
?>

將這個檔案上傳到伺服器,與unzip.php同一個目錄下,
運行 unzip2.php 這個程式。

如果還是不行的話,那就是空間實在不支援,沒有辦法,很對不住您,浪費您的時間.
 ' ;
 echo "check PHP version... " . phpversion() . " -------- OK!<br> " ;
 echo "testing Permission... " ;

 $fp = @fopen("phpzip.test", "wb") ;
 if ( FALSE !== $fp )
 {
  fclose($fp) ;
  @unlink("phpzip.test") ;
 }
 else
 {
  exit("目前的目錄沒有寫的許可權,請將目前的目錄屬性修改為:777 ") ;
 }

 $dir = "phpziptest" ;
 $file = "$dir/test.txt.php" ;
 @mkdir($dir, 0777) ;
 $fp = @fopen($file, "wb") ;
 if ( FALSE === $fp )
 {
  @rmdir($dir) ;
  exit ("沒有許可權在程式建立的檔案夾下建立檔案 ,很可能是PHP安全模式所致,解決方案如下:<p><center><textarea cols=110 rows=15>$safemode</textarea></center>") ;
 }
 @fclose($fp) ;
 @unlink($file) ;
 @rmdir($dir) ;
 echo " ----------------- OK!<br> " ;
}

function HtmlHead($title="", $css教程_file="")
{
 echo "<html> "
  . " "
  . "<head> "
  . "<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> "
  . "<title>$title</title> "
  . "<style type="text/css"> "
  . "body,pre,td {font-size:12px; background-color:#fcfcfc; font-family:Tahoma,verdana,Arial} "
  . "input,textarea{font-size:12px; background-color:#f0f0f0; font-family:Tahoma,verdana,Arial} "
  . "</style> "
  . "</head> "
  . " "
  . "<body> " ;
}

function HtmlFoot()
{
 echo "<center><font size="5" face="楷體_GB2312" color="red">使用完請立即刪除本檔案,以避免被其它人發現使用!</font></center> "
  . "<br><hr color="#003388"> "
  . "<center> "
  . "<p style="font-family:verdana; font-size:12px">Contact us: "
  . "<a href="http://www.111cn.net/" target="_blank">http://www.111cn.net/</a></p> "
  . "</center> "
  . "</body> "
  . " "
  . "</html>" ;
}

?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.