php 在線解壓程序
代碼如下:
<?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.bcty365.com/" target="_blank"><font color="blue">phpZip</font></a>
壓縮文件時,不要選擇“壓縮成Gzip格式”,否則將無法正確解壓!</font>" ;
}
else
{
$gzip_info = "<font color="blue">恭喜! 您的空間支持zlib壓縮,強烈建議用
<a href="http://www.bcty365.com/"><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.bcty365.com/" target="_blank">http://www.phpfensi.com/</a></p> "
. "</center> "
. "</body> "
. " "
. "</html>" ;
}
?>
新聞熱點
疑難解答