当前位置:首页 > 代码 > 正文

php代码压缩(php解压压缩包)

admin 发布:2023-05-13 08:30 130


本篇文章给大家谈谈php代码压缩,以及php解压压缩包对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

(急)php 解压文件(unzip)

1、先下载

2、里面有个 canphp\lib\Zip.class.php 文件,仅仅需要这个文件就行了,这是个压缩与解压缩的类,在需要的地方含态源,包含这个文件即可闭悉使用。

3、使用方法:

(1)压缩:

$zip=new Zip();

$zip-compress('template.zip','template');//将template目录的谈态所有文件压缩到template.zip文件

(2)解压:

$zip=new Zip();

$zip-decompress('template.zip','template2');//将template.zip压缩文件,解压到template2目录 。

4、两种方法的返回值请参考Zip.class.php 或 var_dump 返回值

5、实际测试成功,只是返回一些notice。我的代码如下:

?php

require_once "zip.class.php";

$zip = new Zip();

$zip-compress('xtw.zip', 'template');

$zip-decompress('xtw.zip', 'template2');

?

求php同时上传两张图片并根据时间存入数据库!根据下面的代码来修改!

我给你个简单的吧 这个可以实现三个一起上传衫坦 这个是我自己用的 做了点调整

uploadCore.php 页面代码

?php

/*

* @(#)UploadFile.php (beta) 2005/2/19

*

* exBlog上传附件类,可同时处理用户多个上传文件。效验文件有效性后存储至指定目录。

* 可返回上传文件的相关有用信息供其它程序使用。(如文件名、类型、大小、保存路径)

* 使用方法请见本类底部(UploadFile类使用注释)信息。

*/

class UploadFile {

var $user_post_file = array(); //用户上传的文件

var $user_name_u = array();//username

//var $user_name_y = array(); //usertype

var $save_file_path; //存放用户上传文件的路径

var $max_file_size; //文件最大尺寸

var $last_error; //记录最后一次出错信息

//默认允许用户上传的文件类型

var $allow_type = array('gif', 'jpg', 'png', 'zip', 'rar', 'txt', 'doc', 'pdf');

var $final_file_path; /或厅桐/最终保存的文件名

var $save_info = array(); //返回一组有用信息,用于提示用户。

/**

* 构造函数,用与初始化相关信息,用户待上传文件、存储路径等

*

* @param Array $file 用户上传的文件

* @param String $path 存储用户上传文件的路径

* @param Integer $size 允许用户上传文件的大小(字节)

* @param Array $type 此数组中存放允计用户上传的文件类型

*/

function UploadFile($file, $uname, $path, $size = 2097152, $type = '') {

$this-user_name_u = $uname;

//$this-user_name_y = $utype;

$this-user_post_file = $file;

$this-save_file_path = $path;

$this-max_file_size = $size; //如果用户不填写文件大小,则默认为2M.

if ($type != '')

$this-allow_type = $type;

}

/**

* 存储用户上传文件,检验合法性通过后,存储至指定位置。

* @access public

* @return int 值为0时上传失败,非0表示上传成功的个数。

*/

function upload() {

for ($i = 0; $i count($this-user_post_file['name']); $i++) {

//如果当前文件上传功能,则执行下一步。

if ($this-user_post_file['error'][$i] == 0) {

//取当前文件名、临时文件名、大小、扩展名,后面将用到。

$userty = $this-user_name_y[$i];

$uuname = $this-user_name_u[$i];

$name = $this-user_post_file['name'][$i];

$tmpname = $this-user_post_file['tmp_name'][$i];

$size = $this-user_post_file['size'][$i];

$mime_type = $this-user_post_file['type'][$i];

$type = $this-getFileExt($this-user_post_file['name'][$i]);

//检测当前上传文件大小是否合法。

if (!$this-checkSize($size)) {

$this-last_error = "这个文件的大小太大了. 您上传的文件名: ".$name;

$this-halt($this-last_error);

continue;

}

//检测当前上传文件扩展伏镇名是否合法。

if (!$this-checkuplod($type)) {

$this-last_error = "允许上传文件类型: .".$type." 您上传的文件名: ".$name;

$this-halt($this-last_error);

continue;

}

//检测当前上传文件是否非法提交。

if(!is_uploaded_file($tmpname)) {

$this-last_error = "文件非法提交. 您上传的文件名: ".$name;

$this-halt($this-last_error);

continue;

}

//移动文件后,重命名文件用。

$basename = $this-getBaseName($name, ".".$type);

//移动后的文件名

$saveas = $basename."-".time().".".$type;

//$saveas = $basename.".".$type;

//组合新文件名再存到指定目录下,格式:存储路径 + 文件名 + 时间 + 扩展名

$this-final_file_path = $this-save_file_path."/".$saveas;

if(!move_uploaded_file($tmpname, $this-final_file_path)) {

$this-last_error = $this-user_post_file['error'][$i];

$this-halt($this-last_error);

continue;

}

//存储当前文件的有关信息,以便其它程序调用。

$this-save_info[] = array("uname" = $uuname,"name" = $name, "type" = $type,

"mime_type" = $mime_type,

"size" = $size, "saveas" = $saveas,

"path" = $this-final_file_path);

}

}

return count($this-save_info); //返回上传成功的文件数目

}

/**

* 返回一些有用的信息,以便用于其它地方。

* @access public

* @return Array 返回最终保存的路径

*/

function getSaveInfo() {

return $this-save_info;

}

/**

* 检测用户提交文件大小是否合法

* @param Integer $size 用户上传文件的大小

* @access private

* @return boolean 如果为true说明大小合法,反之不合法

*/

function checkSize($size) {

if ($size $this-max_file_size) {

return false;

}

else {

return true;

}

}

/**

* 检测用户提交文件类型是否合法

* @access private

* @return boolean 如果为true说明类型合法,反之不合法

*/

function checkType($extension) {

foreach ($this-allow_type as $type) {

//echo "pre";

//print_r($type);

//print_r($extension);

$str=substr($extension['name'][0],strrpos($extension['name'][0],'.')+1);

//echo $str;

//exit();

if (strcasecmp($str, $type) == 0)

return true;

}

return false;

}

function checkuplod($extension) {

foreach ($this-allow_type as $type) {

//echo "pre";

//print_r($type);

//print_r($extension);

//$str=substr($extension['name'][0],strrpos($extension['name'][0],'.')+1);

//echo $str;

//exit();

if (strcasecmp($extension, $type) == 0)

return true;

}

return false;

}

/**

* 显示出错信息

* @param $msg 要显示的出错信息

* @access private

*/

function halt($msg) {

printf("bUploadFile Error:/b %s br\n", $msg);

exit();

}

/**

* 取文件扩展名

* @param String $filename 给定要取扩展名的文件

* @access private

* @return String 返回给定文件扩展名

*/

function getFileExt($filename) {

$stuff = pathinfo($filename);

return $stuff['extension'];

}

/**

* 取给定文件文件名,不包括扩展名。

* eg: getBaseName("j:/hexuzhong.jpg"); //返回 hexuzhong

*

* @param String $filename 给定要取文件名的文件

* @access private

* @return String 返回文件名

*/

function getBaseName($filename, $type) {

$basename = basename($filename, $type);

return $basename;

}

}

?

调用和使用方法

$tmp=$Form;

require ('uploadCore.php');

//设置允许用户上传的文件类型。

$type = array('gif', 'jpg', 'png', 'zip', 'rar', 'txt');

//实例化上传类,第一个参数为用户上传的文件组、第二个参数为存储路径、

//第三个参数为文件最大大小。如果不填则默认为2M

//第四个参数为充许用户上传的类型数组。如果不填则默认为gif, jpg, png, zip, rar, txt, doc, pdf

$upload = new UploadFile($user_upload_file,$user_name, $pathy, 500000, $type);

//print"pre";

//print_r($upload);

//上传用户文件,返回int值,为上传成功的文件个数。

$num = $upload-upload();

if ($num != 0) {

//echo "上传成功br";

$jeff_upload_info=$upload-getSaveInfo();

//取得文件的有关信息,文件名、类型、大小、路径。用print_r()打印出来。

//print_r($jeff_upload_info['uname']);

//print"pre";

//print_r($jeff_upload_info);

//exit();

//格式为: Array

// (

// [0] = Array(

// [name] = example.txt

// [type] = txt

// [size] = 526

// [path] = j:/tmp/example-1108898806.txt

// )

// )

//获得文件保存路径或者其他的信息

for ($jeff_upload_success_num = 0; $jeff_upload_success_num $num; $jeff_upload_success_num++)

{

$tmp['zz_upload_file'] = $jeff_upload_info[$jeff_upload_success_num]['uname'];

$tmp['zz_user_name'] = $jeff_upload_info[$jeff_upload_success_num]['name'];

$tmp['zz_user_uname'] = $jeff_upload_info[$jeff_upload_success_num]['saveas'];

$tmp['zz_size'] = $jeff_upload_info[$jeff_upload_success_num]['size'];

$tmp['zz_addtime'] = date("Y-m-d");

$tmp['zz_passtime'] = date("Y-m-d");

//print"pre";

//print_r($tmp);

$q_sql = data_insert($tmp,'hczb_zzwd');//插入数据库类

//print_r($q_sql);

//$jeff_upload_success_url = "\r\n".'

'.$jeff_upload_info[$jeff_upload_success_num]['path'].'[/img]';

//$jeff_upload_success_img .= $jeff_upload_success_url; //获得

代码

}

if($q_sql)

{

echo "scriptwindow.location.href='third.php';/script";

$_SESSION['f'] = 3;

}

else

{

echo "scriptalert('sorry,操作失败');window.location.href='third.php';/script";;

}

//echo $num."个文件上传成功";

}

else {

echo "scriptalert('sorry,上传失败,允许上传的格式是:'".$type."'');window.location.href='third.php';/script";

}

表单调用:

table width="91%" border="0" align="center" cellpadding="0" cellspacing="0" style="margin-top:12px;"

tr

td valign="top" fieldset

legendimg src="images/third_11.jpg" //legend

table width="98%" border="0" cellspacing="0" cellpadding="0" style="margin-top:12px;" align="center"

tr

td class="tianjie"table width="100%" border="0" cellspacing="0" cellpadding="0"

tr

td width="16%" align="center"附件序号 /td

td width="34%" align="center"附件名称 /td

td width="43%" align="center"附件说明/td

td width="7%" align="center" /td

/tr

/table

table width="100%" border="0" cellspacing="0" cellpadding="0"

tr

td width="16%" align="center"附件一 /td

td width="38%" align="center"input name="user_upload_file[]" type="file" class="bg" id="filename" size="16" //td

td width="43%" align="center"table width="100%" border="0" cellspacing="0" cellpadding="0"

tr

td width="10" align="right"img src="images/input_l.gif" width="6" height="28" //td

td width="120"

input name="user_name[]" type="text" id="user_name" class="srk" size="35" onchange="clear_errors(document.all.dis_error_user_name,this);"/ /td

td width="9" align="left"img src="images/input_r.gif" width="5" height="28" //td

/tr

/table/td

td width="3%" align="center" /td

/tr

/table

table width="100%" border="0" cellspacing="0" cellpadding="0" class="lx"

tr

td width="16%" align="center"附件二 /td

td width="38%" align="center"input name="user_upload_file[]" type="file" class="bg" id="filename" size="16" //td

td width="43%" align="center"table width="100%" border="0" cellspacing="0" cellpadding="0"

tr

td width="10" align="right"img src="images/input_l.gif" width="6" height="28" //td

td width="120"

input name="user_name[]" type="text" id="user_name1" class="srk" size="35" onchange="clear_errors(document.all.dis_error_user_nameo,this);"/ /td

td width="9" align="left"img src="images/input_r.gif" width="5" height="28" //td

/tr

/table/td

td width="3%" align="center" /td

/tr

/table

table width="100%" border="0" cellspacing="0" cellpadding="0"

tr

td width="16%" align="center"附件三 /td

td width="38%" align="center"input name="user_upload_file[]" type="file" class="bg" id="filename" size="16" //td

td width="43%" align="center"table width="100%" border="0" cellspacing="0" cellpadding="0"

tr

td width="10" align="right"img src="images/input_l.gif" width="6" height="28" //td

td width="120"

input name="user_name[]" type="text" id="user_name2" class="srk" size="35" onchange="clear_errors(document.all.dis_error_user_namet,this);"/ /td

td width="9" align="left"img src="images/input_r.gif" width="5" height="28" //td

/tr

/table/td

td width="3%" align="center" /td

/tr

/table

table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin:15px;"

tr

td align="center"input type="submit" name="sub" value=" " style="border:0px; width:166px; height:28px; background:url(images/third_19.jpg) no-repeat; cursor:hand" //td

/tr

/table

/td

/tr

/table

/fieldset/td

/tr

/table

有哪里不明白的 M我 告诉你

php代码压缩的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php解压压缩包、php代码压缩的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/44771.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载