PHP的zip 使用方法
PHP的zip 使用方法
在Zip文件功能可以让你阅读ZIP文件。
-------------------------------------------------- ------------------------------
安装
对于Zip文件的职能工作,您的服务器,这些图书馆必须安装:
该ZZIPlib库吉Draheim :下载ZZIPlib图书馆
邮编PELC的延伸:下载的Zip PELC延长
安装Linux系统
PHP的5 + :邮政编码职能和邮编图书馆默认情况下不启用的,必须从上面的联系。使用-w ith-拉链=方向配置选项,包括邮政编码的支持。
Windows系统下的安装
PHP的5 + :邮政编码职能默认情况下不启用,所以php_zip.dll和ZZIPlib图书馆必须从上面的连结。 php_zip.dll必须启用内部的php.ini 。
为了使任何PHP扩展, PHP的extension_dir设置(在php.ini文件)应设置的目录下的PHP扩展库的位置。例如extension_dir值是c : PHP的分机。
-------------------------------------------------- ------------------------------
PHP的Zip文件功能
PHP的:显示最早的PHP版本,支持的功能。
Function | Description | PHP |
---|---|---|
zip_close() | Closes a ZIP file | 4 |
zip_entry_close() | Closes an entry in the ZIP file | 4 |
zip_entry_compressedsize() | Returns the compressed size of an entry in the ZIP file | 4 |
zip_entry_compressionmethod() | Returns the compression method of an entry in the ZIP file | 4 |
zip_entry_filesize() | Returns the actual file size of an entry in the ZIP file | 4 |
zip_entry_name() | Returns the name of an entry in the ZIP file | 4 |
zip_entry_open() | Opens an entry in the ZIP file for reading | 4 |
zip_entry_read() | Reads from an open entry in the ZIP file | 4 |
zip_open() | Opens a ZIP file | 4 |
zip_read() | Reads the next entry in a ZIP file | 4 |
PHP FTP 函数使用教程
该功能提供的FTP客户端访问文件服务器通过文件传输协议( FTP ) 。
该FTP函数是用来打开,登录名和密切的联系,以及上传,下载,重命名,删除和获取信息的文件从文件服务器。并不是所有的FTP功能将与每一个服务器或返回同样的结果。该FTP函数成为可与PHP 3 。
这些功能都是为了详细访问FTP服务器。如果你只希望阅读或写入文件在FTP服务器上,可以考虑使用包装的ftp://与文件的功能。
安装
PHP的Windows版本内置了支持的FTP延长。因此, FTP函数将自动工作。
然而,如果您运行的是Linux版本的PHP中,你将不得不与编译PHP -启用-的F TP( P HP4中+ )或- wi th-的F T P(P H P3中)得到的F T P职能工作。
PHP的FTP函数
PHP的:显示最早的PHP版本,支持的功能。
Function | Description | PHP |
---|---|---|
ftp_alloc() | Allocates space for a file to be uploaded to the FTP server | 5 |
ftp_cdup() | Changes the current directory to the parent directory on the FTP server | 3 |
ftp_chdir() | Changes the current directory on the FTP server | 3 |
ftp_chmod() | Sets permissions on a file via FTP | 5 |
ftp_close() | Closes an FTP connection | 4 |
ftp_connect() | Opens an FTP connection | 3 |
ftp_delete() | Deletes a file on the FTP server | 3 |
ftp_exec() | Executes a program/command on the FTP server | 4 |
ftp_fget() | Downloads a file from the FTP server and saves it to an open file | 3 |
ftp_fput() | Uploads from an open file and saves it to a file on the FTP server | 3 |
ftp_get_option() | Returns runtime behaviors of the FTP connection | 4 |
ftp_get() | Downloads a file from the FTP server | 3 |
ftp_login() | Logs on to an FTP connection | 3 |
ftp_mdtm() | Returns the last modified time of a specified file | 3 |
ftp_mkdir() | Creates a new directory on the FTP server | 3 |
ftp_nb_continue() | Continues retrieving/sending a file (non-blocking) | 4 |
ftp_nb_fget() | Downloads a file from the FTP server and saves it to an open file (non-blocking) | 4 |
ftp_nb_fput() | Uploads from an open file and saves it to a file on the FTP server (non-blocking) | 4 |
ftp_nb_get() | Downloads a file from the FTP server (non-blocking) | 4 |
ftp_nb_put() | Uploads a file to the FTP server (non-blocking) | 4 |
ftp_nlist() | Lists the files in a specified directory on the FTP server | 3 |
ftp_pasv() | Turns passive mode on or off | 3 |
ftp_put() | Uploads a file to the FTP server | 3 |
ftp_pwd() | Returns the current directory name | 3 |
ftp_quit() | Alias of ftp_close() | 3 |
ftp_raw() | Sends a raw command to the FTP server | 5 |
ftp_rawlist() | Returns a detailed list of files in the specified directory | 3 |
ftp_rename() | Renames a file or directory on the FTP server | 3 |
ftp_rmdir() | Removes a directory on the FTP server | 3 |
ftp_set_option() | Sets runtime options for the FTP connection | 4 |
ftp_site() | Sends a SITE command to the server | 3 |
ftp_size() | Returns the size of the specified file | 3 |
ftp_ssl_connect() | Opens a secure SSL-FTP connection | 4 |
ftp_systype() | Returns the system type identifier of the FTP server | 3 |
PHP FTP Constants
PHP: indicates the earliest version of PHP that supports the constant.
Constant | Description | PHP |
---|---|---|
FTP_ASCII | 3 | |
FTP_TEXT | 3 | |
FTP_BINARY | 3 | |
FTP_IMAGE | 3 | |
FTP_TIMEOUT_SEC | 3 | |
FTP_AUTOSEEK | 4 | |
FTP_AUTORESUME | Determine resume position and start position for get and put requests automatically | 4 |
FTP_FAILED | Asynchronous transfer has failed | 4 |
FTP_FINISHED | Asynchronous transfer has finished | 4 |
FTP_MOREDATA | Asynchronous transfer is still active | 4 |
class yl_upload_class
{
#*********************************************************
#创建目录函数
#*********************************************************
function createfolder($yl_path)
{
if (!file_exists($yl_path))
{
$this -> createfolder(dirname($yl_path));
@mkdir($yl_path, 0777);
}
return $this -> createfolder;
}
#*********************************************************
#获取文件名称,大小,类型,临时文件名
#*********************************************************
function yl_getfilename($yl_type)
{
global $yl_filedata,$yl_directroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
return $_FILES[$yl_filedata][$yl_type];
}
#*********************************************************
#获取文件大小
#*********************************************************
function yl_getfilesize()
{
global $yl_filedata,$yl_directroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
if($this -> yl_getfilename('size') == 0){
$this -> alert("请选择上传文件!");
exit;
}
if($this -> yl_getfilename('size') > $yl_maxsize){
$yl_maxsizek=$yl_maxsize/1024;
$this -> alert("上传文件超出限制范围$yl_maxsizek.K!");
exit;
}
switch (strtolower($yl_sizeformat)){
case 'b':
return $this -> yl_getfilename('size') . ' B';
break;
case 'k':
return ($this -> yl_getfilename('size')/1024) . ' K';
break;
case 'm':
return ($this -> yl_getfilename('size'))/(1024*1024) . ' M';
}
}
#*********************************************************
#获得文件扩展名
#*********************************************************
function yl_getfiletype()
{
global $yl_filedata,$yl_directroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
$yl_temp_arr = explode(".", $this -> yl_getfilename('name'));
$yl_file_ext = array_pop($yl_temp_arr);
$yl_file_ext = trim($yl_file_ext);
$yl_file_ext = strtolower($yl_file_ext);
//检查扩展名
if (in_array($yl_file_ext, $yl_arrext) === false) {
$this -> alert("上传文件类型被限制!");
exit;
}
return $yl_file_ext;
}
#*********************************************************
#上传
#*********************************************************
function yl_uploadfile()
{
global $yl_filedata,$yl_directroy,$file_urldirectroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
$yl_file_nameold = $this -> yl_getfilename('name');//原文件名
$yl_file_namenews = date('Ymd').'_'.md5(date('YmdHis'));//重命名
if($yl_ext == 0){
$yl_file_names = $yl_file_namenews.'.'.$this -> yl_getfiletype();//改名
}elseif ($yl_ext == 1){
$yl_file_names = $yl_file_namenews.'.jpg';//统一改名为jpg
}
$yl_tmp_name = $this -> yl_getfilename('tmp_name');//服务器上临时文件名
$yl_file_size = $this -> yl_getfilesize();//获取文件大小
$yl_file_type = $this -> yl_getfiletype();//获取文件类型
$yl_file_path = $yl_directroy.'/'.$yl_settingsnew;//建立一个目录
//检查目录是否存在,不存在则创建
if(@is_dir($yl_file_path) === false) {
$this -> createfolder(''.$yl_file_path.'');//创建目录
}
//检查是否已上传
if(@is_uploaded_file($yl_tmp_name) === false) {
$this -> alert("文件已上传!");
exit;
}
//检查目录写权限
if (@is_writable($yl_file_path) === false) {
$this -> alert("上传目录没有写权限!");
exit;
}
$yl_doupload = @copy($yl_tmp_name, ''.$yl_file_path.'/'.$yl_file_names.'');
if($yl_doUpload === false)
{
$this -> alert("上传失败!");
}else{
echo '上传成功';
echo '<br>';
echo '文件目录:'.$yl_file_path.'';
echo '<br>';
echo '原文件名:'.$yl_file_nameold.'';
echo '<br>';
echo '新文件名:'.$yl_file_names.'';
echo '<br>';
echo '文件大小:'.$yl_file_size.'';
echo '<br>';
echo '文件类型:'.$yl_file_type.'';
}
return;
}
#*********************************************************
#*删除文件
#*********************************************************
function delfile()
{
global $yl_filedata,$yl_directroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
$yl__dir = dirname(trim($yl_directroy));
if( $this->_isDel( $yl__dir ) )
{
return @unlink( $yl_directroy ) ? true : false;
}else{
return false;
}
}
#*********************************************************
#删除目录 目录下如果有文件不能删除
#*********************************************************
function deldir( )
{
global $yl_filedata,$yl_directroy,$yl_settingsnew;
global $yl_maxsize,$yl_sizeformat,$yl_arrext,$yl_ext;
if( $this->_isdel($yl_directroy) && is_dir( $yl_directroy ) )
{
return @rmdir( $yl_directroy ) ? true : false;
}else{
return false;
}
}
#*********************************************************
#提示
#*********************************************************
function alert($yl_msg)
{
echo '<html>';
echo '<head>';
echo '<title>error</title>';
echo '<meta http-equiv="content-type" c>';
echo '</head>';
echo '<body>';
echo '<script type="text/javascript">alert("'.$yl_msg.'");;</script>';
echo '</body>';
echo '</html>';
exit;
}
}
?>
include "class/config.inc.php"; //把配置文件包含进来
$db = new db;
$db-> db_connect( ); //连接数据库
$user = new user; //初始化
$session = new session;
//启动会话
session_start();
//删除session表中已经过期的用户(即非在线网友)因为此文件总是被调用从而保证显示的都是当前在线的用户
$curtime=time();
$con="lastactivity<$curtime";
$session->del($con);
//正在线的网友需不断更新session表中的lastactivity时间,并重新设置用户的COOKIES
if ($HTTP_SESSION_VARS["online"]=="on"){ //此处也可用$_SESSION[“online”]
$userid=$HTTP_SESSION_VARS["userid"]; //取当前在线用户的userid
$ipaddress=substr($REMOTE_ADDR,0,50);
$lastactivity=time()+3600; //更新最后活动时间,如时一个小时之内未调动页面就认为用户已离线,从而会被删除。
$session->update($userid,$ipaddress,$lastactivity);
}else{
//如果未登录那直接转入登录页面
$firstpage="logon.php";
header ("Location: $firstpage");
exit;
}
insert($userid,$ipaddress,$lastactivity) 把登录成功的用户插入到表中
update($userid,$ipaddress,$lastactivity)更新在线用户最后活动时间
del($con)删除满足条件的用户,用它来清除离线用户
get_from_condition($con) 返回满足查询条件的记录集
if ($hiddenField=="0"){ //测检表单有未被提交
$con="username='$username' and userpwd='$userpwd'";
$result=$user->get_from_condition($con);
if ($user->counter==1){
if (!session_is_registered("online")){//检测是否被登记过
session_register("online"); //登记一个新的变量为会话变量
}
if (!session_is_registered("ccauser")){
session_register("ccauser");
}
if (!session_is_registered("userid")){
session_register("userid");
}
$ccauser=$username; //给会话变量赋值
$online="on"; //这个变量在global.php用到以更新最后活动时间lastactivity
$userid=$user->userid;
$ipaddress=substr($REMOTE_ADDR,0,50);
$lastactivity=time()+3600;
$con=" userid=$userid";
$session->get_from_condition($con);
//判断会话是否存在,有可能你在不同的机器上登两次。
if ($session->counter==1){
$session->update($userid,$ipaddress,$lastactivity); //如存在,更新
}else{
$session->insert($userid,$ipaddress,$lastactivity); //如不存在,插入
}
//在客户机设置COOKIES
SetCookie("ccauser",$username,time()+3600);
Header("Location:test.php");//然后导向测试页
}
}
?>
if($HTTP_SESSION_VARS["online"]=="") { //判断是否已登录
?>
//下面是登录的表单
名称:
密码:
}else{
echo "网友:".$HTTP_COOKIE_VARS["ccauser"]."你已经登录了"; //如果已登录则显示提示
$str="
退出社区";
echo $str;
}
?>
include "global.php"; //把global.php文件包含进来
$strWelcome="欢迎".$_SESSION['ccauser']."
";
echo $strWelcome; //显示欢迎信息
$str=” 当前在线用户:
===================
”;
$con=" 1=1";
//提出session表中所有记录即是当前在线用户,未把游客算在内
$result=$session->get_from_condition($con);
while($row=mysql_fetch_array($result)){
$con1="userid=$row[userid]";
$user->get_from_condition($con1);
$str.=$user->username." ";
}
echo $str;
?>
退出社区
允许用户上传文件是必要的,许多网站,所以,我们如何做到这一点,正是?但话又说回来,有一些方便的书面文件上。审议了麻烦呢?那么,这里的一些帮助是稍微更容易消化。
首先,您需要HTML网页的形式将谎言。这种形式必须确定文件最大规模的上传,并必须有文件上传领域本身
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="submit" value="Send File" />
</form>
MAX_FILE_SIZE界定的尽可能多的文件大小,以字节为单位,当然。名称属性上传领域(指定的档案价值的type属性)的重要组成部分,正如我们稍后将使用此在我们的脚本来知道哪些要上传的文件(这是用来支持多种上传) 。
下一步,我们要上传文件。但首先,重要的是要理解美元_FILE [ ]数组。
在美元_FILE [ ]数组,有一个项目,每一个领域中上传的形式发送用户此脚本。因此,在我们的案例,有一个指数命名为' userfield ' ,为一个外地与这个名字在我们的形式。每个值的数组也是一个关联数组,以下项和值(改写明确从文件) :
<?php
$target_file = '/path/to/upload/'.basename($_FILES['userfile']['name']);
?>
关键价值
'名称'文件名使用客户的计算机。
'型'的MIME类型的文件(如图像/ gif格式) 。该浏览器并不总是提供这方面的,和价值不应假定是正确的。
'大小'的大小上传的文件(以字节为单位) 。
' tmp_name '的文件给上传的文件,其中应立即转移,并更名后的成功上传。地点是无关紧要的,因为你使用的方法把文件( move_uploaded_file ,我使用后)都知道的位置。
'错误'的错误代码(或成功的代码,如果0 )的问题发生在上传。 (错误代码)
表1 :简要介绍了钥匙和价值观
所以,现在我们可以开始进行业务。首先,我们得到的文件名,我们将想给上传的文件,而且目录,我们希望把它。
<?php
$target_file = '/path/to/upload/'.basename($_FILES['userfile']['name']);
?>
使用basename是绝对必要的。没有这一点,您正在运行一个巨大的安全风险。如果用户要上传文件的名称,开始使用相对路径上升,如../../../, ,他们最终将得到根除,可以随时随地浏览到的文件的落实更多的目录后,原来的起点的道路。
警告:这是非常重要的是,可以确保服务器的权限写信给这个目录。如果您的服务器正在运行的任何发行版的Linux或Mac OS X ,您可能会需要属性的目录。
下一步,您只需将上传的文件为target_file 。我认为这样做的,如果为了试验的成功。
<?php
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $target_file)) {
// Succeeded
echo 'Yay!';
} else {
// Failed
echo 'No!';
}
?>
这真的就是这么回事。很简单,啊?您可以展开这一点,通过阅读PHP的文件序列和unserializing对象。如果您有任何疑问,可随时张贴的论坛。
相关文章
php 中file_get_contents超时问题的解决方法
file_get_contents超时我知道最多的原因就是你机器访问远程机器过慢,导致php脚本超时了,但也有其它很多原因,下面我来总结file_get_contents超时问题的解决方法总结。...2016-11-25- php如何实现抓取网页图片,相较于手动的粘贴复制,使用小程序要方便快捷多了,喜欢编程的人总会喜欢制作一些简单有用的小软件,最近就参考了网上一个php抓取图片代码,封装了一个php远程抓取图片的类,测试了一下,效果还不错分享...2015-10-30
- 有时为了网站安全和版权问题,会对自己写的php源码进行加密,在php加密技术上最常用的是zend公司的zend guard 加密软件,现在我们来图文讲解一下。 下面就简单说说如何...2016-11-25
- 相信很多站长都遇到过这样一个问题,访问页面时出现408错误,下面一聚教程网将为大家介绍408错误出现的原因以及408错误的解决办法。 HTTP 408错误出现原因: HTT...2017-01-22
- 下面我们来看一篇关于Android子控件超出父控件的范围显示出来方法,希望这篇文章能够帮助到各位朋友,有碰到此问题的朋友可以进来看看哦。 <RelativeLayout xmlns:an...2016-10-02
- 这篇文章主要介绍了源码分析系列之json_encode()如何转化一个对象,对json_encode()感兴趣的同学,可以参考下...2021-04-22
- ps软件是现在很多人都会使用到的,HSL面板在ps软件中又有着非常独特的作用。这次文章就给大家介绍下ps怎么使用HSL面板,还不知道使用方法的下面一起来看看。  ...2017-07-06
- ps软件是现在非常受大家喜欢的一款软件,有着非常不错的使用功能。这次文章就给大家介绍下ps把文字背景变透明的操作方法,喜欢的一起来看看。 1、使用Photoshop软件...2017-07-06
- PHP去除html、css样式、js格式的方法很多,但发现,它们基本都有一个弊端:空格往往清除不了 经过不断的研究,最终找到了一个理想的去除html包括空格css样式、js 的PHP函数。...2013-08-02
intellij idea快速查看当前类中的所有方法(推荐)
这篇文章主要介绍了intellij idea快速查看当前类中的所有方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-09-02- 1.在没有设置默认值的情况下: 复制代码 代码如下:SELECT userinfo.id, user_name, role, adm_regionid, region_name , create_timeFROM userinfoLEFT JOIN region ON userinfo.adm_regionid = region.id 结果:...2014-05-31
js导出table数据到excel即导出为EXCEL文档的方法
复制代码 代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta ht...2013-10-13- 批量更新mysql更新语句很简单,更新一条数据的某个字段,一般这样写:复制代码 代码如下:UPDATE mytable SET myfield = 'value' WHERE other_field = 'other_value';如果更新同一字段为同一个值,mysql也很简单,修改下where即...2013-10-04
- ps软件是一款非常不错的图片处理软件,有着非常不错的使用效果。这次文章要给大家介绍的是ps怎么制作倒影,一起来看看设计倒影的方法。 用ps怎么做倒影最终效果̳...2017-07-06
- 许多的朋友对于Plesk控制面板应用不是非常的了解特别是英文版的Plesk控制面板,在这里小编整理了一些关于Plesk控制面板常用的使用方案整理,具体如下。 本文基于Linu...2016-10-10
- 本文涉及的主题虽然很基础,在许多人看来属于小伎俩,但在JavaScript基础知识中属于一个综合性的话题。这里会涉及到对象属性的封装、原型、构造函数、闭包以及立即执行表达式等知识。公有方法 公有方法就是能被外部访问...2015-11-08
安卓手机wifi打不开修复教程,安卓手机wifi打不开解决方法
手机wifi打不开?让小编来告诉你如何解决。还不知道的朋友快来看看。 手机wifi是现在生活中最常用的手机功能,但是遇到手机wifi打不开的情况该怎么办呢?如果手机wifi...2016-12-21- 最近想自学PHP ,做了个验证码,但不知道怎么搞的,总出现一个如下图的小红叉,但验证码就是显示不出来,原因如下 未修改之前,出现如下错误; (1)修改步骤如下,原因如下,原因是apache权限没开, (2)点击打开php.int., 搜索extension=ph...2013-10-04
使用insertAfter()方法在现有元素后添加一个新元素
复制代码 代码如下: //在现有元素后添加一个新元素 function insertAfter(newElement, targetElement){ var parent = targetElement.parentNode; if (parent.lastChild == targetElement){ parent.appendChild(newEl...2014-05-31- 单个字符分割 string s="abcdeabcdeabcde"; string[] sArray=s.Split('c'); foreach(string i in sArray) Console.WriteLine(i.ToString()); 输出下面的结果: ab de...2020-06-25