PHP FTP 函数使用教程

 更新时间:2016年11月25日 16:30  点击:1317

PHP FTP 函数使用教程

引进的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

PHP and AJAX Suggest

这个suggest是仿google的效果了,google总是走在世界的技术的前面啊,下面我们也来看看实例吧.

先看看html文件.

<form> 
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
下面用js文件的ajax文件来处理数据.
var xmlHttp;

function showHint(str)
{
if (str.length==0)
  { 
  document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  } 
var url="gethint.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
 } 
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
 
这个文件只是返回php处理的数据,而我们的php文件如下.
<?php
// Fill up array with names
$a[]="Anna";
$a[]="Brittany";
$a[]="Cinderella";
$a[]="Diana";
$a[]="Eva";
$a[]="Fiona";
$a[]="Gunda";
$a[]="Hege";
$a[]="Inga";
$a[]="Johanna";
$a[]="Kitty";
$a[]="Linda";
$a[]="Nina";
$a[]="Ophelia";
$a[]="Petunia";
$a[]="Amanda";
$a[]="Raquel";
$a[]="Cindy";
$a[]="Doris";
$a[]="Eve";
$a[]="Evita";
$a[]="Sunniva";
$a[]="Tove";
$a[]="Unni";
$a[]="Violet";
$a[]="Liza";
$a[]="Elizabeth";
$a[]="Ellen";
$a[]="Wenche";
$a[]="Vicky";
//get the q parameter from URL
$q=$_GET["q"];
//lookup all hints from array if length of q>0
if (strlen($q) > 0)
{
$hint="";
for($i=0; $i<count($a); $i++)
  {
  if (strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))
    {
    if ($hint=="")
      {
      $hint=$a[$i];
      }
    else
      {
      $hint=$hint." , ".$a[$i];
      }
    }
  }
}

//Set output to "no suggestion" if no hint were found
//or to the correct values
if ($hint == "")
{
$response="no suggestion";
}
else
{
$response=$hint;
}

//output the response
echo $response;
?>
好了我们的确suggest效果就完成了.

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

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;
?>

退出社区

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • 图解PHP使用Zend Guard 6.0加密方法教程

    有时为了网站安全和版权问题,会对自己写的php源码进行加密,在php加密技术上最常用的是zend公司的zend guard 加密软件,现在我们来图文讲解一下。 下面就简单说说如何...2016-11-25
  • Python中的imread()函数用法说明

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • ps怎么使用HSL面板

    ps软件是现在很多人都会使用到的,HSL面板在ps软件中又有着非常独特的作用。这次文章就给大家介绍下ps怎么使用HSL面板,还不知道使用方法的下面一起来看看。 &#8195;...2017-07-06
  • Plesk控制面板新手使用手册总结

    许多的朋友对于Plesk控制面板应用不是非常的了解特别是英文版的Plesk控制面板,在这里小编整理了一些关于Plesk控制面板常用的使用方案整理,具体如下。 本文基于Linu...2016-10-10
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • 使用insertAfter()方法在现有元素后添加一个新元素

    复制代码 代码如下: //在现有元素后添加一个新元素 function insertAfter(newElement, targetElement){ var parent = targetElement.parentNode; if (parent.lastChild == targetElement){ parent.appendChild(newEl...2014-05-31
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • 使用GruntJS构建Web程序之构建篇

    大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
  • 使用percona-toolkit操作MySQL的实用命令小结

    1.pt-archiver 功能介绍: 将mysql数据库中表的记录归档到另外一个表或者文件 用法介绍: pt-archiver [OPTION...] --source DSN --where WHERE 这个工具只是归档旧的数据,不会对线上数据的OLTP查询造成太大影响,你可以将...2015-11-24
  • 如何使用php脚本给html中引用的js和css路径打上版本号

    在搜索引擎中搜索关键字.htaccess 缓存,你可以搜索到很多关于设置网站文件缓存的教程,通过设置可以将css、js等不太经常更新的文件缓存在浏览器端,这样访客每次访问你的网站的时候,浏览器就可以从浏览器的缓存中获取css、...2015-11-24
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)

    strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
  • jQuery 1.9使用$.support替代$.browser的使用方法

    jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support 。 在更新的 2.0 版本中,将不再支持 IE 6/7/8。 以后,如果用户需要支持 IE 6/7/8,只能使用 jQuery 1.9。 如果要全面支持 IE,并混合...2014-05-31
  • MySQL日志分析软件mysqlsla的安装和使用教程

    一、下载 mysqlsla [root@localhost tmp]# wget http://hackmysql.com/scripts/mysqlsla-2.03.tar.gz--19:45:45-- http://hackmysql.com/scripts/mysqlsla-2.03.tar.gzResolving hackmysql.com... 64.13.232.157Conn...2015-11-24
  • C#注释的一些使用方法浅谈

    C#注释的一些使用方法浅谈,需要的朋友可以参考一下...2020-06-25