Archive

Archive for the ‘PHP’ Category

php缩略图类

2011-09-04 留下评论

require_once(‘bmp.php’);
/*
* Created on 20:31 2011-8-2
* Author : LKK , http://lianq.net
* 使用方法:
*$resizeimage = new myThumbClass($file_name,120,90,$thumb,0,0); //生成120×90大小
*$resizeimage = new myThumbClass($file_name,1,2,$thumb,1,233); //生成高,宽之中最大233
*$resizeimage = new myThumbClass($file_name,660,1,$thumb,-1,0); //生成宽度660
*$resizeimage = new myThumbClass($file_name,1,660,$thumb,-1,0); //生成高度660
*注意:新高度或新宽度都不能为0
*/
class myThumbClass{
public $sur_file; //读取的原图片
public $des_file; //生成目标图片
public $tem_file; //临时图片
public $tag; //缩略标签 0,默认,按固定的高宽生成 1,按比列或固定最大长度生成 -1,按某个宽度或某个高度缩小
public $resize_width; //$tag为0时,目标文件宽
public $resize_height; //$tag为0时,目标文件高
public $sca_max; //$tag为1时,<0$sca_max<1时为缩小比例;$sca_max>1时为最大长度(高或宽之中的最大值)
public $type; //图片类型
public $width; //原图片宽
public $height; //原图片高
//构造函数
public function __construct($surpic, $reswid, $reshei, $despic, $mark, $scamax){
$this->sur_file = $surpic;
$this->resize_width = $reswid;
$this->resize_height = $reshei;
$this->tag = $mark;
$this->sca_max = $scamax;
$this->type = strtolower(substr(strrchr($this->sur_file,”.”),1)); //获取图片类型
$this->init_img(); //初始化图片
$this->des_file = $despic; //目标图片地址
$this->width = imagesx($this->tem_file);
$this->height = imagesy($this->tem_file);
$this->new_img();
imagedestroy($this->tem_file);
}
//图片初始化函数
private function init_img(){
if($this->type == ‘jpeg’){
$this->tem_file = imagecreatefromjpeg($this->sur_file);
}elseif($this->type == ‘jpg’){
$this->tem_file = imagecreatefromjpeg($this->sur_file);
}elseif($this->type == ‘gif’){
$this->tem_file = imagecreatefromgif($this->sur_file);
}elseif($this->type == ‘png’){
$this->tem_file = imagecreatefrompng($this->sur_file);
}elseif($this->type == ‘bmp’){
$this->tem_file = imagecreatefrombmp($this->sur_file); //bmp.php中包含
}
}
//图片生成函数
private function new_img(){
$ratio = ($this->width)/($this->height); //原图比例
$resize_ratio = ($this->resize_width)/($this->resize_height); //缩略后比例
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);//生成新图片
if($this->tag == 0){ //按固定高宽截取缩略图
$newimg = imagecreatetruecolor($this->resize_width,$this->resize_height);//生成新图片
if($ratio>=$resize_ratio){//即等比例下,缩略图的高比原图长,因此高不变
imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width,$this->resize_height, (($this->height)*$resize_ratio), $this->height);
}elseif($ratio<$resize_ratio){//即等比例下,缩略图的宽比原图长,因此宽不变
imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width,$this->resize_height, $this->width, (($this->width)/$resize_ratio));
}
}elseif($this->tag == 1){ //按固定比例或最大长度缩小
if($this->sca_max < 1){ //按比例缩小
$newimg = imagecreatetruecolor((($this->width)*($this->sca_max)),(($this->height)*($this->sca_max)));//生成新图片
imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, (($this->width)*($this->sca_max)), (($this->height)*($this->sca_max)), $this->width, $this->height);
}elseif($this->sca_max > 1){ //按某个最大长度缩小
if($ratio>=1){ //宽比高长
$newimg = imagecreatetruecolor($this->sca_max,($this->sca_max/$ratio));//生成新图片
imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->sca_max,($this->sca_max/$ratio), $this->width, $this->height);
}else{
$newimg = imagecreatetruecolor(($this->sca_max*$ratio),$this->sca_max);//生成新图片
imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, ($this->sca_max*$ratio),$this->sca_max, $this->width, $this->height);
}
}
}elseif($this->tag == -1){ //按某个宽度或某个高度缩小
if($resize_ratio>=1){//新高小于新宽,则图片按新宽度缩小
$newimg = imagecreatetruecolor($this->resize_width,($this->resize_width/$ratio));//生成新图片
imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, $this->resize_width,($this->resize_width/$ratio), $this->width, $this->height);
}elseif($resize_ratio<1){//新宽小于新高,则图片按新高度缩小
$newimg = imagecreatetruecolor(($this->resize_height*$ratio),$this->resize_height);//生成新图片
imagecopyresampled($newimg, $this->tem_file, 0, 0, 0, 0, ($this->resize_height*$ratio),$this->resize_height, $this->width, $this->height);
}
}
//输出新图片
if($this->type == ‘jpeg’ || $this->type == ‘jpg’){
imagejpeg($newimg,$this->des_file);
}elseif($this->type == ‘gif’){
imagegif($newimg,$this->des_file);
}elseif($this->type == ‘png’){
imagepng($newimg,$this->des_file);
}elseif($this->type == ‘bmp’){
imagebmp($newimg,$this->des_file);//bmp.php中包含
}
}#function new_img() end
}#end class

Advertisements
分类:PHP 标签:

PHP排序算法类

2011-08-22 留下评论

sort.php

<?php
/**
* 四种排序算法设计(PHP)
*
* 1) 插入排序(Insertion Sort)的基本思想是:
每次将一个待排序的记录,按其关键字大小插入到前面已经排好序的子文件中的适当位置,直到全部记录插入完成为止。
2) 选择排序(Selection Sort)的基本思想是:
每一趟从待排序的记录中选出关键字最小的记录,顺序放在已排好序的子文件的最后,直到全部记录排序完毕。
3) 冒泡排序的基本思想是:
两两比较待排序记录的关键字,发现两个记录的次序相反时即进行交换,直到没有反序的记录为止。
4) 快速排序实质上和冒泡排序一样,都是属于交换排序的一种应用。所以基本思想和上面的冒泡排序是一样的。
*
* @author quanshuidingdang
*/
class Sort {
private $arr = array();
private $sort = ‘insert’;
private $marker = ‘_sort’;

private $debug = TRUE;

/**
* 构造函数
*
* @param array 例如: $config = array (
‘arr’ => array(22,3,41,18) , //需要排序的数组值
‘sort’ => ‘insert’, //可能值: insert, select, bubble, quick
‘debug’ => TRUE //可能值: TRUE, FALSE
)
*/
public function __construct($config = array()) {
if ( count($config) > 0) {
$this->_init($config);
}
}

/**
* 获取排序结果
*/
public function display() {
return $this->arr;
}

/**
* 初始化
*
* @param array
* @return bool
*/
private function _init($config = array()) {
//参数判断
if ( !is_array($config) OR count($config) == 0) {
if ($this->debug === TRUE) {
$this->_log(“sort_init_param_invaild”);
}
return FALSE;
}

//初始化成员变量
foreach ($config as $key => $val) {
if ( isset($this->$key)) {
$this->$key = $val;
}
}

//调用相应的成员方法完成排序
$method = $this->sort . $this->marker;
if ( ! method_exists($this, $method)) {
if ($this->debug === TRUE) {
$this->_log(“sort_method_invaild”);
}
return FALSE;
}

if ( FALSE === ($this->arr = $this->$method($this->arr)))
return FALSE;
return TRUE;
}

/**
* 插入排序
*
* @param array
* @return bool
*/
private function insert_sort($arr) {
//参数判断
if ( ! is_array($arr) OR count($arr) == 0) {
if ($this->debug === TRUE) {
$this->_log(“sort_array(insert)_invaild”);
}
return FALSE;
}

//具体实现
$count = count($arr);
for ($i = 1; $i < $count; $i++) {
$tmp = $arr[$i];
for($j = $i-1; $j >= 0; $j–) {
if($arr[$j] > $tmp) {
$arr[$j+1] = $arr[$j];
$arr[$j] = $tmp;
}
}
}
return $arr;
}

/**
* 选择排序
*
* @param array
* @return bool
*/
private function select_sort($arr) {
//参数判断
if ( ! is_array($arr) OR count($arr) == 0) {
if ($this->debug === TRUE) {
$this->_log(“sort_array(select)_invaild”);
}
return FALSE;
}

//具体实现
$count = count($arr);
for ($i = 0; $i < $count-1; $i++) {
$min = $i;
for ($j = $i+1; $j < $count; $j++) {
if ($arr[$min] > $arr[$j]) $min = $j;
}
if ($min != $i) {
$tmp = $arr[$min];
$arr[$min] = $arr[$i];
$arr[$i] = $tmp;
}
}
return $arr;
}

/**
* 冒泡排序
*
* @param array
* @return bool
*/
private function bubble_sort($arr) {
//参数判断
if ( ! is_array($arr) OR count($arr) == 0) {
if ($this->debug === TRUE) {
$this->_log(“sort_array(bubble)_invaild”);
}
return FALSE;
}

//具体实现
$count = count($arr);
for ($i = 0; $i < $count; $i++) {
for ($j = $count-1; $j > $i; $j–) {
if ($arr[$j] < $arr[$j-1]) {
$tmp = $arr[$j];
$arr[$j] = $arr[$j-1];
$arr[$j-1] = $tmp;
}
}
}
return $arr;
}

/**
* 快速排序
*
* @param array
* @return bool
*/
private function quick_sort($arr) {
//具体实现
if (count($arr) <= 1) return $arr;
$key = $arr[0];
$left_arr = array();
$right_arr = array();
for ($i = 1; $i < count($arr); $i++){
if ($arr[$i] <= $key)
$left_arr[] = $arr[$i];
else
$right_arr[] = $arr[$i];
}
$left_arr = $this->quick_sort($left_arr);
$right_arr = $this->quick_sort($right_arr);

return array_merge($left_arr, array($key), $right_arr);
}

/**
* 日志记录
*/
private function _log($msg) {
$msg = ‘date[‘ . date(‘Y-m-d H:i:s’) . ‘] ‘ . $msg . ‘\n’;
return @file_put_contents(‘sort_err.log’, $msg, FILE_APPEND);
}
}

/*End of file sort.php*/
/*Location htdocs/sort.php */

sort_demo.php

<?php

require_once(‘sort.php’);

$config = array (
‘arr’ => array(23, 22, 41, 18, 20, 12, 200303,2200,1192) , //需要排序的数组值
‘sort’ => ‘select’, //可能值: insert, select, bubble, quick
‘debug’ => TRUE //可能值: TRUE, FALSE
);

$sort = new Sort($config);
//var_dump($config[‘arr’]);
var_dump($sort->display());

/*End of php*/

分类:PHP 标签:,

英文反向链接分析工具 SEO Elite4.0 附破解版下载地址

2011-08-21 留下评论

英文版的SEO Elite反向链接分析工具,分析网站反向链接各个因素,

基本功能如下:

分析链接的文字(锚文本)、链接页面的PR值、链接页面的外部链接数、和链接质量等等

新建任务或者打开程序以后会有一个初始化的设置界面,第一个是让你填分析种类的。这个是用特定的搜索引擎分析反向链接,也可以查关键词在搜索引擎排名位置的,搜索引擎收录页面数量的,甚至还可以查出来有多少个网站链接到你网站上的。呵呵

1.填上要分析的网站域名
2.选择要返回的最大记录集数 根据个人情况来选择吧。
3.选择搜索引擎
4.只返回那些包含我们所提供关键词的网站
5.选择要排除分析范围的网站
6.其他的一些特定参数

这个工具在运行分析的时候3个报告显示界面都可以同步信息过滤。
现在看线程分析页面 Threads View

这里只显示3个环节 信息来源网站 运行过程 状态
一般都会先从搜索引擎去获取第一批分析资源

最主要的是报告分析页面 Report View
首先看一下最重要的分析参数“链接描述”
phpchina.com的Google优化还是比较成功的,搜索PHP结果比php.net都靠前=,=
其他的一些重要参数比如PR值和不同IP数量等。

如果这些数据你看起来比较头晕可以直接看分析页面Analysis View
看一下body、title、Anchor标签内的关键字分析情况

SEO Elite 4.0破解版下载地址:http://dl.dbank.com/c0dejt4w43

PHP文件上传代码

2011-08-21 留下评论

<?php
// basic php file upload example
// http://php.snippetdb.com

if ($_POST[‘upload’]){ //process uploaded file
$uploadDir = ‘/domains/path-com/path/www_root/_crop/full-’; //file upload path
$uploadFile = $uploadDir . $_FILES[‘uploadfile’][‘name’];
echo “<pre>”;
if (move_uploaded_file($_FILES[‘uploadfile’][‘tmp_name’], $uploadFile) )
{
echo “File is valid, and was successfully uploaded. “;
echo “Here’s some more debugging info:\n”;
}
else
{
echo “ERROR! Here’s some debugging info:\n”;
echo “remember to check valid path, max filesize\n”;
echo “$-POST-upload: “.$_POST[‘upload’];
}
echo “</pre>”;

} else { //display upload form
?>
<form enctype=”multipart/form-data” action=”<?php echo $_SERVER[‘SCRIPT_NAME’]?>” method=”post”>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”1111024000″>
<br>
<input name=”uploadfile” type=”file”>
<br>
<input name= “upload” type=”submit” value=”Upload File”>
</form>
<?php
}
?>

分类:PHP 标签:,

PHP网站备份程序

2011-08-21 留下评论

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>网站程序备份</title>
</head>
<body>
<form name=”myform” method=”post” action=””>
<?php
error_reporting(E_ALL & ~E_NOTICE);
ini_set(‘memory_limit’, ‘2048M’);
echo “选择要压缩的文件或目录:<br>”;
$fdir = opendir(‘./’);
while($file=readdir($fdir))
{
if($file==’.’|| $file==’..’)
continue;
echo “<input name=’dfile[]’ type=’checkbox’ value=’$file’ “.($file==basename(__FILE__)?””:”checked”).”> “;

if(is_file($file))
{
echo “<font face=\”wingdings\” size=\”5\”>2</font>&nbsp;&nbsp;$file<br>”;
}
else
{
echo “<font face=\”wingdings\” size=\”5\”>0</font>&nbsp;$file<br>”;
}
}
?>
<br>
包含下列文件类型:
<input name=”file_type” type=”text” id=”file_type” value=”” size=”50″>
<font color=”red”>
(文件类型用”|”隔开,默认空则包含任意文件,例:如果需要打包php和jpg文件,则输入”php|jpg”)
</font>
<br>
压缩文件保存到目录:
<input name=”todir” type=”text” id=”todir” value=”__dwb2011__” size=”15″>
<font color=”red”>
(留空为本目录,必须有写入权限)
</font>
<br>
压缩文件名称:
<input name=”zipname” type=”text” id=”zipname” value=”dwb2011.zip” size=”15″>
<font color=”red”>
(.zip)
</font>
<br>
<br>
<input name=”myaction” type=”hidden” id=”myaction” value=”dozip”>
<input type=’button’ value=’反选’ onclick=’selrev();’>
<input type=”submit” name=”Submit” value=” 开始压缩 “>
<script language=’javascript’>
function selrev()
{
with(document.myform)
{
for(i=0;i<elements.length;i++)
{
thiselm = elements[i];
if(thiselm.name.match(/dfile\[]/))
thiselm.checked = !thiselm.checked;
}
}
}
</script>

<?php
error_reporting(E_ALL & ~E_NOTICE);
set_time_limit(0);
class PHPzip
{
var $file_count = 0 ;
var $datastr_len   = 0;
var $dirstr_len = 0;
var $filedata = ”; //该变量只被类外部程序访问
var $gzfilename;
var $fp;
var $dirstr=”;
var $filefilters = array();

function SetFileFilter($filetype)
{
$this->filefilters = explode(‘|’,$filetype);
}

//返回文件的修改时间格式.
//只为本类内部函数调用.
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 startfile($path = ‘dodo.zip’)
{
$this->gzfilename=$path;
$mypathdir=array();

do
{
$mypathdir[] = $path = dirname($path);
}    while($path != ‘.’);

@end($mypathdir);

do
{
$path = @current($mypathdir);
@mkdir($path);
}    while(@prev($mypathdir));

if($this->fp=@fopen($this->gzfilename,”w”))
{
return true;
}

return false;
}

//添加一个文件到 zip 压缩包中.
function addfile($data, $name)
{
$name = str_replace(‘\’, ‘/’, $name);
if(strrchr($name,’/’)==’/’)
return $this->adddir($name);
if(!empty($this->filefilters))
{
if (!in_array(end(explode(“.”,$name)), $this->filefilters))
{
return;
}
}
$dtime = dechex($this->unix2DosTime());
$hexdtime = ‘\x’ . $dtime[6] . $dtime[7] . ‘\x’ . $dtime[4] . $dtime[5] . ‘\x’ . $dtime[2] . $dtime[3] . ‘\x’ . $dtime[0] . $dtime[1];
eval(‘$hexdtime = “‘ . $hexdtime . ‘”;’);

$unc_len = strlen($data);
$crc     = crc32($data);
$zdata   = gzcompress($data);
$c_len   = strlen($zdata);
$zdata   = substr(substr($zdata, 0, strlen($zdata) – 4), 2);

//新添文件内容格式化:
$datastr  = “\x50\x4b\x03\x04”;
$datastr .= “\x14\x00”;            // ver needed to extract
$datastr .= “\x00\x00”;            // gen purpose bit flag
$datastr .= “\x08\x00”;            // compression method
$datastr .= $hexdtime;             // last mod time and date
$datastr .= pack(‘V’, $crc);             // crc32
$datastr .= pack(‘V’, $c_len);           // compressed filesize
$datastr .= pack(‘V’, $unc_len);         // uncompressed filesize
$datastr .= pack(‘v’, strlen($name));    // length of filename
$datastr .= pack(‘v’, 0);                // extra field length
$datastr .= $name;
$datastr .= $zdata;
$datastr .= pack(‘V’, $crc);                 // crc32
$datastr .= pack(‘V’, $c_len);               // compressed filesize
$datastr .= pack(‘V’, $unc_len);             // uncompressed filesize
fwrite($this->fp,$datastr); //写入新的文件内容
$my_datastr_len = strlen($datastr);
unset($datastr);

//新添文件目录信息
$dirstr  = “\x50\x4b\x01\x02”;
$dirstr .= “\x00\x00”;                 // version made by
$dirstr .= “\x14\x00”;                 // version needed to extract
$dirstr .= “\x00\x00”;                 // gen purpose bit flag
$dirstr .= “\x08\x00”;                 // compression method
$dirstr .= $hexdtime;                  // last mod time & date
$dirstr .= pack(‘V’, $crc);            // crc32
$dirstr .= pack(‘V’, $c_len);          // compressed filesize
$dirstr .= pack(‘V’, $unc_len);        // uncompressed filesize
$dirstr .= pack(‘v’, strlen($name) );  // length of filename
$dirstr .= pack(‘v’, 0 );              // extra field length
$dirstr .= pack(‘v’, 0 );              // file comment length
$dirstr .= pack(‘v’, 0 );              // disk number start
$dirstr .= pack(‘v’, 0 );              // internal file attributes
$dirstr .= pack(‘V’, 32 );             // external file attributes – ‘archive’ bit set
$dirstr .= pack(‘V’,$this->datastr_len ); // relative offset of local header
$dirstr .= $name;
$this->dirstr .= $dirstr; //目录信息
$this -> file_count ++;
$this -> dirstr_len += strlen($dirstr);
$this -> datastr_len += $my_datastr_len;
}

function adddir($name)
{
$name = str_replace(“\\”, “/”, $name);
$datastr = “\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00”;
$datastr .= pack(“V”,0).pack(“V”,0).pack(“V”,0).pack(“v”, strlen($name) );
$datastr .= pack(“v”, 0 ).$name.pack(“V”, 0).pack(“V”, 0).pack(“V”, 0);
fwrite($this->fp,$datastr); //写入新的文件内容
$my_datastr_len = strlen($datastr);
unset($datastr);
$dirstr = “\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00”;
$dirstr .= pack(“V”,0).pack(“V”,0).pack(“V”,0).pack(“v”, strlen($name) );
$dirstr .= pack(“v”, 0 ).pack(“v”, 0 ).pack(“v”, 0 ).pack(“v”, 0 );
$dirstr .= pack(“V”, 16 ).pack(“V”,$this->datastr_len).$name;
$this->dirstr .= $dirstr; //目录信息
$this -> file_count ++;
$this -> dirstr_len += strlen($dirstr);
$this -> datastr_len += $my_datastr_len;
}

function createfile()
{
//压缩包结束信息,包括文件总数,目录信息读取指针位置等信息
$endstr = “\x50\x4b\x05\x06\x00\x00\x00\x00” .
pack(‘v’, $this -> file_count) .
pack(‘v’, $this -> file_count) .
pack(‘V’, $this -> dirstr_len) .
pack(‘V’, $this -> datastr_len) .
“\x00\x00”;
fwrite($this->fp,$this->dirstr.$endstr);
fclose($this->fp);
}
}

if(!trim($_REQUEST[zipname]))
$_REQUEST[zipname] = “dodozip.zip”;
else
$_REQUEST[zipname] = trim($_REQUEST[zipname]);

if(!strrchr(strtolower($_REQUEST[zipname]),’.’)==’.zip’)
$_REQUEST[zipname] .= “.zip”;

$_REQUEST[todir] = str_replace(‘\’,’/’,trim($_REQUEST[todir]));

if(!strrchr(strtolower($_REQUEST[todir]),’/’)==’/’)
$_REQUEST[todir] .= “/”;

if($_REQUEST[todir]==”/”)
$_REQUEST[todir] = “./”;

function listfiles($dir=”.”)
{
global $dodozip;
$sub_file_num = 0;
if(is_file(“$dir”))
{
if(realpath($dodozip ->gzfilename)!=realpath(“$dir”))
{
$dodozip -> addfile(implode(”,file(“$dir”)),”$dir”);
return 1;
}
return 0;
}

$handle=opendir(“$dir”);
while ($file = readdir($handle))
{
if($file==”.”||$file==”..”)
continue;

if(is_dir(“$dir/$file”))
{
$sub_file_num += listfiles(“$dir/$file”);
}
else
{
if(realpath($dodozip ->gzfilename)!=realpath(“$dir/$file”))
{
$dodozip -> addfile(implode(”,file(“$dir/$file”)),”$dir/$file”);
$sub_file_num ++;
}
}
}

closedir($handle);

if(!$sub_file_num)
$dodozip -> addfile(“”,”$dir/”);

return $sub_file_num;
}

function num_bitunit($num)
{
$bitunit=array(‘ B’,’ KB’,’ MB’,’ GB’);
for($key=0;$key<count($bitunit);$key++)
{
if($num>=pow(2,10*$key)-1)
{ //1023B 会显示为 1KB
$num_bitunit_str=(ceil($num/pow(2,10*$key)*100)/100).” $bitunit[$key]”;
}
}
return $num_bitunit_str;
}

if(is_array($_REQUEST[dfile]))
{
$dodozip = new PHPzip;
if($_REQUEST[“file_type”] != NULL)
$dodozip -> SetFileFilter($_REQUEST[“file_type”]);
if($dodozip -> startfile(“$_REQUEST[todir]$_REQUEST[zipname]”))
{
echo “正在添加压缩文件…<br><br>”;
$filenum = 0;
foreach($_REQUEST[dfile] as $file)
{
if(is_file($file))
{
if(!empty($dodozip -> filefilters))
if (!in_array(end(explode(“.”,$file)), $dodozip -> filefilters))
continue;
echo “<font face=\”wingdings\” size=\”5\”>2</font>&nbsp;&nbsp;$file<br>”;
}
else
{
echo “<font face=\”wingdings\” size=\”5\”>0</font>&nbsp;$file<br>”;
}
$filenum += listfiles($file);
}
$dodozip -> createfile();

echo “<br>压缩完成,共添加 $filenum 个文件.<br><a href=’$_REQUEST[todir]$_REQUEST[zipname]’ _fcksavedurl=’$_REQUEST[todir]$_REQUEST[zipname]’>$_REQUEST[todir]$_REQUEST[zipname] (“.num_bitunit(filesize(“$_REQUEST[todir]$_REQUEST[zipname]”)).”)</a>”;
}
else
{
echo “$_REQUEST[todir]$_REQUEST[zipname] 不能写入,请检查路径或权限是否正确.<br>”;
}
}
?>
</form>
</body>
</html>

分类:PHP 标签:, ,

PHP 在线输出PDF文件

2011-07-27 留下评论

<?php

if(!function_exists(‘read_pdf’)) {

function read_pdf($file) {

if(strtolower(substr(strrchr($file,’.’),1)) != ‘pdf’) {

echo ‘文件格式不对.’;

return;

}

if(!file_exists($file)) {

echo ‘文件不存在’;

return;

}

header(‘Content-type: application/pdf’);

header(‘filename=’.$file);

readfile($file);

}

}

/*End of PHP*/

分类:PHP 标签:,

php 利用cookie在客户端记录浏览历史

2011-07-27 留下评论

/* 记录浏览历史 */
if (!empty($_COOKIE[‘history’]))
{
if(stripos($_COOKIE[‘history’].’,’,$goods_id.’,’)===false){

$history = explode(‘,’, $_COOKIE[‘history’]);

array_unshift($history, $goods_id); //入栈

while (count($history) > 5) //大于容器容量
{
array_pop($history); //出栈
}

setcookie(‘history’, implode(‘,’, $history), gmtime() + 3600 * 24 * 30);
}
}
else
{
setcookie(‘history’, $goods_id, gmtime() + 3600 * 24 * 30);
}

分类:PHP 标签:,