/*
$Id: PHPZip.php
*/
class PHPZip {
var $datasec = array();
var $ctrl_dir = array();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0;
function Zip($dir, $zipfilename) {
if (@function_exists('gzcompress')) {
@set_time_limit("0");
$this->openFile($dir,$dir);
$out = $this -> filezip();
$fp = fopen($zipfilename, "w");
fwrite($fp, $out, strlen($out));
fclose($fp);
}
}
function openFile($path, $zipName) {
$temp_path = $path;
$temp_zip_path = $zipName;
$zipDir = $zipName;
if ($handle = @opendir($path)) {
while (false !== ($file = readdir($handle))) {
if($file !='.' and $file !='..'){
if(ereg('\.' , $file.@basename())) {
$fd = fopen($path.'/'.$file, "r");
$fileValue = @fread ($fd, 1024000);
fclose ($fd);
$this -> addFile($fileValue, $zipName . '/' . $file);
} else {
$this ->openFile($path.'/'.$file, $zipName . '/' . $file);
}
}
}
$zipName = $temp_zip_path;
$path = $temp_path;
closedir($handle);
}
}
function unix2DosTime($unixtime = 0) {
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
if ($timearray['year'] < 1980) {
$timearray['year'] = 1980;
$timearray['mon'] = 1;
$timearray['mday'] = 1;
$timearray['hours'] = 0;
$timearray['minutes'] = 0;
$timearray['seconds'] = 0;
}
return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
}
function addFile($data, $name, $time = 0) {
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->unix2DosTime($time));
$hexdtime = '\x' . $dtime[6] . $dtime[7]
. '\x' . $dtime[4] . $dtime[5]
. '\x' . $dtime[2] . $dtime[3]
. '\x' . $dtime[0] . $dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');
$fr = "\x50\x4b\x03\x04";
$fr .= "\x14\x00";
$fr .= "\x00\x00";
$fr .= "\x08\x00";
$fr .= $hexdtime;
$unc_len = strlen($data);
$crc = crc32($data);
$zdata = gzcompress($data);
$c_len = strlen($zdata);
$zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
$fr .= pack('V', $crc);
$fr .= pack('V', $c_len);
$fr .= pack('V', $unc_len);
$fr .= pack('v', strlen($name));
$fr .= pack('v', 0);
$fr .= $name;
$fr .= $zdata;
$fr .= pack('V', $crc);
$fr .= pack('V', $c_len);
$fr .= pack('V', $unc_len);
$this -> datasec[] = $fr;
$new_offset = strlen(implode('', $this->datasec));
$cdrec = "\x50\x4b\x01\x02";
$cdrec .= "\x00\x00";
$cdrec .= "\x14\x00";
$cdrec .= "\x00\x00";
$cdrec .= "\x08\x00";
$cdrec .= $hexdtime;
$cdrec .= pack('V', $crc);
$cdrec .= pack('V', $c_len);
$cdrec .= pack('V', $unc_len);
$cdrec .= pack('v', strlen($name) );
$cdrec .= pack('v', 0 );
$cdrec .= pack('v', 0 );
$cdrec .= pack('v', 0 );
$cdrec .= pack('v', 0 );
$cdrec .= pack('V', 32 );
$cdrec .= pack('V', $this -> old_offset );
$this -> old_offset = $new_offset;
$cdrec .= $name;
$this -> ctrl_dir[] = $cdrec;
}
function filezip() {
$data = implode('', $this -> datasec);
$ctrldir = implode('', $this -> ctrl_dir);
return
$data .
$ctrldir .
$this -> eof_ctrl_dir .
pack('v', sizeof($this -> ctrl_dir)) .
pack('v', sizeof($this -> ctrl_dir)) .
pack('V', strlen($ctrldir)) .
pack('V', strlen($data)) .
"\x00\x00";
}
}
|
/*
CKEditor_upload.php
monkee
2009-11-15 16:47
*/
$config=array();
$config['type']=array("flash","img"); //上传允许type值
$config['img']=array("jpg","bmp","gif"); //img允许后缀
$config['flash']=array("flv","swf"); //flash允许后缀
$config['flash_size']=200; //上传flash大小上限 单位:KB
$config['img_size']=500; //上传img大小上限 单位:KB
$config['message']="上传成功"; //上传成功后显示的消息,若为空则不显示
$config['name']=mktime(); //上传后的文件命名规则 这里以unix时间戳来命名
$config['flash_dir']="/ckeditor/upload/flash"; //上传flash文件地址 采用绝对地址 方便upload.php文件放在站内的任何位置 后面不加"/"
$config['img_dir']="/ckeditor/upload/img"; //上传img文件地址 采用绝对地址 采用绝对地址 方便upload.php文件放在站内的任何位置 后面不加"/"
$config['site_url']=""; //网站的网址 这与图片上传后的地址有关 最后不加"/" 可留空
//文件上传
uploadfile();
function uploadfile()
{
global $config;
//判断是否是非法调用
if(empty($_GET['CKEditorFuncNum']))
mkhtml(1,"","错误的功能调用请求");
$fn=$_GET['CKEditorFuncNum'];
if(!in_array($_GET['type'],$config['type']))
mkhtml(1,"","错误的文件调用请求");
$type=$_GET['type'];
if(is_uploaded_file($_FILES['upload']['tmp_name']))
{
//判断上传文件是否允许
$filearr=pathinfo($_FILES['upload']['name']);
$filetype=$filearr["extension"];
if(!in_array($filetype,$config[$type]))
mkhtml($fn,"","错误的文件类型!");
//判断文件大小是否符合要求
if($_FILES['upload']['size']>$config[$type."_size"]*1024)
mkhtml($fn,"","上传的文件不能超过".$config[$type."_size"]."KB!");
//$filearr=explode(".",$_FILES['upload']['name']);
//$filetype=$filearr[count($filearr)-1];
$file_abso=$config[$type."_dir"]."/".$config['name'].".".$filetype;
$file_host=$_SERVER['DOCUMENT_ROOT'].$file_abso;
if(move_uploaded_file($_FILES['upload']['tmp_name'],$file_host))
{
mkhtml($fn,$config['site_url'].$file_abso,$config['message']);
}
else
{
mkhtml($fn,"","文件上传失败,请检查上传目录设置和目录读写权限");
}
}
}
//输出js调用
function mkhtml($fn,$fileurl,$message)
{
$str='<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction('.$fn.', \''.$fileurl.'\', \''.$message.'\');</script>';
exit($str);
}
|
/**
* author: askie
* blog: http://www.pkphp.com
* 版权: 随便用
* 无限分类
*/
class Tree
{
public $data=array();
public $cateArray=array();
function Tree()
{
}
function setNode ($id, $parent, $value)
{
$parent = $parent?$parent:0;
$this->data[$id] = $value;
$this->cateArray[$id] = $parent;
}
function getChildsTree($id=0)
{
$childs=array();
foreach ($this->cateArray as $child=>$parent)
{
if ($parent==$id)
{
$childs[$child]=$this->getChildsTree($child);
}
}
return $childs;
}
function getChilds($id=0)
{
$childArray=array();
$childs=$this->getChild($id);
foreach ($childs as $child)
{
$childArray[]=$child;
$childArray=array_merge($childArray,$this->getChilds($child));
}
return $childArray;
}
function getChild($id)
{
$childs=array();
foreach ($this->cateArray as $child=>$parent)
{
if ($parent==$id)
{
$childs[$child]=$child;
}
}
return $childs;
}
//单线获取父节点
function getNodeLever($id)
{
$parents=array();
if (key_exists($this->cateArray[$id],$this->cateArray))
{
$parents[]=$this->cateArray[$id];
$parents=array_merge($parents,$this->getNodeLever($this->cateArray[$id]));
}
return $parents;
}
function getLayer($id,$preStr='|-')
{
return str_repeat($preStr,count($this->getNodeLever($id)));
}
function getValue ($id)
{
return $this->data[$id];
} // end func
}
/*$Tree = new Tree("请选择分类");
//setNode(目录ID,上级ID,目录名字);
$Tree->setNode(1, 0, '目录1');
$Tree->setNode(2, 1, '目录2');
$Tree->setNode(5, 3, '目录5');
$Tree->setNode(3, 0, '目录3');
$Tree->setNode(4, 2, '目录4');
$Tree->setNode(9, 4, '目录9');
$Tree->setNode(6, 2, '目录6');
$Tree->setNode(7, 2, '目录7');
$Tree->setNode(8, 3, '目录8');
//print_r($Tree->getChildsTree(0));
//print_r($Tree->getChild(0));
//print_r($Tree->getLayer(2));
$category = $Tree->getChilds();
//遍历输出
foreach ($category as $key=>$id)
{
echo $id.$Tree->getLayer($id, '|-').$Tree->getValue($id)."\n";
}*/
?>
|