Note This PHP tutorial file compression Code he would like to use the Zip.exe file Oh, so we have to take out the Zip.exe compressed files out OH.
if (! IsSet ($_get[' dirname '))
{
Show_input_form ();
}
Else
{
Check if empty
if (Empty ($_get[' dirname '))
{
Hg_exit ("Please enter the folder name!");
}
Check valid dirname
if (FALSE!== strpos ($_get[' dirname '), "/"))
{
Hg_exit (""/"is an illegal folder name!");
}
if (FALSE!== strstr ($_get[' dirname '), ".."))
{
Hg_exit ("": "is an illegal folder name!");
}
Check valid dir
if (!is_dir ($_get[' dirname '))
{
Hg_exit ("" {$_get[' dirname '} "is not a valid folder!");
}
$szData = "";
$szInfo = "";
$file _count = @ZipDir ($_get[' dirname '), & $szData, & $szInfo);
$info _size_16byte = @sprintf ("%016d", @strlen ($szInfo));
$szData = @sprintf ("%016d", $file _count). $info _size_16byte. $szInfo. $szData;
$filename = $_get[' dirname '). ". Dat";
if (function_exists (Gzencode))
{
$szData = Gzencode ($szData);
$filename. = ". Gz";
}
Header ("Content-type:application/octet-stream");
Header ("Accept-ranges:bytes");
Header ("Accept-length:".) Strlen ($szData));
Header ("content-disposition:attachment; Filename= $filename ");
Echo $szData;
}
function Show_input_form ()
{
echo htmlhead ("File Pack");
echo "n";
echo "n";
Echo Htmlfoot ();
}
function Zipdir ($szDirName, & $szData, & $szInfo)
{
Write Dir header
$szInfo. = "$szDirName | [Dir]n];
$file _count = 0;
$hDir = Opendir ($szDirName);
while ($file = ReadDir ($hDir))
{
if ($file = = "." | | $file = = "..") continue;
$szCurFile = "$szDirName/$file";
if (Is_dir ($szCurFile))
{
$file _count + = Zipdir ($szCurFile, & $szData, & $szInfo);
}
else if (Is_file ($szCurFile))
{
$hCurFile = fopen ($szCurFile, "RB");
$size = FileSize ($szCurFile);
$szStream = Fread ($hCurFile, $size);
Fclose ($hCurFile);
$file _count++;
Write info
$szInfo. = "$szCurFile | $sizen";
Write Data
$szData. = $szStream;
}
}
Write dir footer
$szInfo. = "$szDirName | [/dir]n];
return $file _count;
}
function Hg_exit ($STR)
{
Echo HtmlHead ("Error, exit!");
echo "
" . $str. "
" ;
Echo Htmlfoot ();
Exit;
}
function HtmlHead ($title)
{
Return "nnn"
. " N"
. " N"
. "NNNN";
}
function Htmlfoot ()
{
Return to Copyright (). "NNN";
}
function Copyright ()
{
Return "
Please delete this file immediately after use to avoid being discovered by others! N
. "
N
. " N
. "
Contact Us:n "
. "http://www.bkjia.com/
N
. " N
. "N
. N
. "" ;
}
?>
http://www.bkjia.com/PHPjc/444927.html www.bkjia.com true http://www.bkjia.com/PHPjc/444927.html techarticle Note This php tutorial file compression Code he would like to use the Zip.exe file Oh, so we have to take the Zip.exe compressed files out Oh. php if (! IsSet ($_get[' dirname ')) {Show_input_f ...