Online File extraction using php

Source: Internet
Author: User

<? Php
// Verify the password
$ Password = "123456 ";
?>
<Html> <Title> Faisun_unzip-pure space-www.softpure.com </title>
<Style type = "text/css"> <! --
Body, td {
Font-size: 14px;
Color: #000000;
}
A {
Color: #000066;
Text-decoration: none;
}
A: hover {
Color: # FF6600;
Text-decoration: underline;
}
-->
</Style>
</Head>

<Body>
<Form name = "myform" method = "post" action = "<? =$ _ SERVER [PHP_SELF];?> "Enctype =" multipart/form-data "onSubmit =" return check_uploadObject (this); ">
<?
If (! $ _ REQUEST ["myaction"]):
?>

<Script language = "javascript">
Function check_uploadObject (form ){
If (form. password. value = ''){
Alert ('enter your password .');
Return false;
}
Return true;
}
</Script>

<Table width = "100%" border = "0" cellspacing = "0" cellpadding = "4">
<Tr>
<Td height = "40" colspan = "2" style = "color: # FF9900 "> <p> <font color =" # FF0000 "> faisun_unzip-decompress the ZIP file program V1.0 online </font> </p>
<P> reprinted, please note: by <a href = "http://www.softpure.com/" target = "_ blank"> pure space </a> (<a href = "http://www.softpure.com/" target = "_ blank"> http://www.softpure.com </a>) supplied by: faisun (<a href = "mailto: faisun@sina.com"> faisun@sina.com </a> ). </p>
<P> usage: Upload the zip file to the same directory of the file through FTP, select the zip file, or click browse... to upload the zip file. </P>
<P> the extracted results retain the original directory structure. </P>
<P> </td>
</Tr>
<Tr>
<Td width = "11%"> select ZIP file: </td>
<Td width = "89%"> <select name = "zipfile">
<Option value = "" selected>-select-</option>
<?
$ Fdir = opendir ('./');
While ($ file = readdir ($ fdir )){
If (! Is_file ($ file) continue;
If (preg_match ('/. zip $/mis', $ file )){
Echo "<option value = '$ file'> $ file </option> rn ";
}
}
?>
</Select> </td>
</Tr>
<Tr>
<Td width = "11%" nowrap> or upload a file: </td>
<Td width = "89%"> <input name = "upfile" type = "file" id = "upfile" size = "20"> </td>
</Tr>
<Tr>
<Td> decompress the package to the directory: </td>
<Td> <input name = "todir" type = "text" id = "todir" value = "_ unzipfiles _" size = "15">
(Leave this directory empty and you must have the write permission) </td>
</Tr>
<Tr>
<Td> Verification password: </td>
<Td> <input name = "password" type = "password" id = "password" size = "15">
(Password set in the source file) </td>
</Tr>
<Tr>
<Td> <input name = "myaction" type = "hidden" id = "myaction" value = "dounzip"> </td>
<Td> <input type = "submit" name = "Submit" value = "decompress"> </td>
</Tr>
</Table>

<?

Elseif ($ _ REQUEST ["myaction"] = "dounzip "):


Class zip
{

Var $ total_files = 0;
Var $ total_folders = 0;

Function Extract ($ zn, $ to, $ index = Array (-1 ))
{
$ OK = 0; $ zip = @ fopen ($ zn, 'rb ');
If (! $ Zip) return (-1 );
$ Cdir = $ this-> ReadCentralDir ($ zip, $ zn );
$ Pos_entry = $ cdir ['offset'];

If (! Is_array ($ index) {$ index = array ($ index );}
For ($ I = 0; $ index [$ I]; $ I ++ ){
If (intval ($ index [$ I])! = $ Index [$ I] & #124; & #124; $ index [$ I]> $ cdir ['entries'])
Return (-1 );
}
For ($ I = 0; $ I <$ cdir ['entries']; $ I ++)
{
@ Fseek ($ zip, $ pos_entry );
$ Header = $ this-> ReadCentralFileHeaders ($ zip );
$ Header ['index'] = $ I; $ pos_entry = ftell ($ zip );
@ Rewind ($ zip); fseek ($ zip, $ header ['offset']);
If (in_array ("-1", $ index) & #124; & #124; in_array ($ I, $ index ))
$ Stat [$ header ['filename'] = $ this-> ExtractFile ($ header, $ to, $ zip );
}
Fclose ($ zip );
Return $ stat;
}

Function ReadFileHeader ($ zip)
{
$ Binary_data = fread ($ zip, 30 );
$ Data = unpack ('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len ', $ binary_data );

$ Header ['filename'] = fread ($ zip, $ data ['filename _ len']);
If ($ data ['extra _ len']! = 0 ){
$ Header ['extra '] = fread ($ zip, $ data ['extra _ len']);
} Else {$ header ['extra '] = '';}

$ Header ['compression'] = $ data ['compression']; $ header ['SIZE'] = $ data ['SIZE'];
$ Header ['compressed _ size'] = $ data ['compressed _ size'];
$ Header ['crc '] = $ data ['crc']; $ header ['flag'] = $ data ['flag'];
$ Header ['mdate'] = $ data ['mdate']; $ header ['mtime'] = $ data ['mtime'];

If ($ header ['mdate'] & $ header ['mtime']) {
$ Hour = ($ header ['mtime'] & 0xF800)> 11; $ minute = ($ header ['mtime'] & 0x07E0)> 5;
$ Seconde = ($ header ['mtime'] & 0x001F) * 2; $ year = ($ header ['mdate'] & 0xFE00)> 9) + 1980;
$ Month = ($ header ['mdate'] & 0x01E0)> 5; $ day = $ header ['mdate'] & 0x001F;
$ Header ['mtime'] = mktime ($ hour, $ minute, $ seconde, $ month, $ day, $ year );
} Else {$ header ['mtime'] = time ();}

$ Header ['stored _ filename'] = $ header ['filename'];
$ Header ['status'] = "OK ";
Return $ header;
}

Function ReadCentralFileHeaders ($ zip ){
$ Binary_data = fread ($ zip, 46 );
$ Header = unpack ('vchkid/vid/vversion/kernel/vflag/vcompression/vmtime/vmdate/Vcrc/kernel/Vsize/kernel/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/ voffset ', $ binary_data );

If ($ header ['filename _ len']! = 0)
$ Header ['filename'] = fread ($ zip, $ header ['filename _ len']);
Else $ header ['filename'] = '';

If ($ header ['extra _ len']! = 0)
$ Header ['extra '] = fread ($ zip, $ header ['extra _ len']);
Else $ header ['extra '] = '';

If ($ header ['comment _ len']! = 0)
$ Header ['comment'] = fread ($ zip, $ header ['comment _ len']);
Else $ header ['comment'] = '';

If ($ header ['mdate'] & $ header ['mtime'])
{
$ Hour = ($ header ['mtime'] & 0xF800)> 11;
$ Minute = ($ header ['mtime'] & 0x07E0)> 5;
$ Seconde = ($ header ['mtime'] & 0x001F) * 2;
$ Year = ($ header ['mdate'] & 0xFE00)> 9) + 1980;
$ Month = ($ header ['mdate'] & 0x01E0)> 5;
$ Day = $ header ['mdate'] & 0x001F;
$ Header ['mtime'] = mktime ($ hour, $ minute, $ seconde, $ month, $ day, $ year );
} Else {
$ Header ['mtime'] = time ();
}
$ Header ['stored _ filename'] = $ header ['filename'];
$ Header ['status'] = 'OK ';
If (substr ($ header ['filename'],-1) = '/')
$ Header ['external '] = 0x41FF0010;
Return $ header;
}

Function ReadCentralDir ($ zip, $ zip_name ){
$ Size = filesize ($ zip_name );

If ($ size <277) $ maximum_size = $ size;
Else $ maximum_size = 277;

@ Fseek ($ zip, $ size-$ maximum_size );
$ Pos = ftell ($ zip); $ bytes = 0x00000000;

While ($ pos <$ size ){
$ Byte = @ fread ($ zip, 1); $ bytes = ($ bytes <8) & #124; ord ($ byte );
If ($ bytes = 0x504b0506 or $ bytes = 0x2e706870504b0506) {$ pos ++; break;} $ pos ++;
}

$ Fdata = fread ($ zip, 18 );

$ Data = @ unpack ('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size ', $ fdata );

If ($ data ['comment _ size']! = 0) $ centd ['comment'] = fread ($ zip, $ data ['comment _ size']);
Else $ centd ['comment'] = ''; $ centd ['entries'] = $ data ['entries'];
$ Centd ['disk _ entries'] = $ data ['disk _ entries'];
$ Centd ['offset'] = $ data ['offset']; $ centd ['disk _ start'] = $ data ['disk _ start'];
$ Centd ['SIZE'] = $ data ['SIZE']; $ centd ['disk'] = $ data ['disk'];
Return $ centd;
}

Function ExtractFile ($ header, $ to, $ zip ){
$ Header = $ this-> readfileheader ($ zip );

If (substr ($ to,-1 )! = "/") $ To. = "/";
If ($ to = './') $ to = '';
$ Pth = explode ("/", $ to. $ header ['filename']);
$ Mydir = '';
For ($ I = 0; $ I <count ($ pth)-1; $ I ++ ){
If (! $ Pth [$ I]) continue;
$ Mydir. = $ pth [$ I]. "/";
If ((! Is_dir ($ mydir) & @ mkdir ($ mydir, 0777) & #124; & #124; ($ mydir = $. $ header ['filename'] & #124; & #124; ($ mydir = $ to & $ this-> total_folders = 0 )) & is_dir ($ mydir ))){
@ Chmod ($ mydir, 0777 );
$ This-> total_folders ++;
Echo "<input name = 'dfile [] 'Type = 'checkbox' value = '$ mydir' checked> <a href =' $ mydir' target = '_ blank'> directory: $ mydir </a> <br> ";
}
}

If (strrchr ($ header ['filename'], '/') = '/') return;

If (! ($ Header ['external '] = 0x41FF0010 )&&! ($ Header ['external '] = 16 )){
If ($ header ['compression'] = 0 ){
$ Fp = @ fopen ($ to. $ header ['filename'], 'wb ');
If (! $ Fp) return (-1 );
$ Size = $ header ['compressed _ size'];

While ($ size! = 0 ){
$ Read_size = ($ size <2048? $ Size: 2048 );
$ Buffer = fread ($ zip, $ read_size );
$ Binary_data = pack ('A'. $ read_size, $ buffer );
@ Fwrite ($ fp, $ binary_data, $ read_size );
$ Size-= $ read_size;
}
Fclose ($ fp );
Touch ($ to. $ header ['filename'], $ header ['mtime']);
} Else {
$ Fp = @fopen($to.w.header='filename'{.'.gz ', 'wb ');
If (! $ Fp) return (-1 );
$ Binary_data = pack ('va1a1va1a1 ', 0x8b1f, Chr ($ header ['compression']),
Chr (0x00), time (), Chr (0x00), Chr (3 ));

Fwrite ($ fp, $ binary_data, 10 );
$ Size = $ header ['compressed _ size'];

While ($ size! = 0 ){
$ Read_size = ($ size <1024? $ Size: 1024 );
$ Buffer = fread ($ zip, $ read_size );
$ Binary_data = pack ('A'. $ read_size, $ buffer );
@ Fwrite ($ fp, $ binary_data, $ read_size );
$ Size-= $ read_size;
}

$ Binary_data = pack ('vv ', $ header ['crc'], $ header ['SIZE']);
Fwrite ($ fp, $ binary_data, 8); fclose ($ fp );

$ Gzp = @gzopen({to.w.header='filename'{.'.gz ', 'rb') or die ("Cette archive est compress

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.