PHP如何使用ftp_close()函数?代码实例

2021年3月25日12:46:18 发表评论 702 次浏览

ftp_close()函数PHP中的内置函数, 用于关闭与指定FTP服务器或主机的现有FTP连接。

语法如下:

ftp_close( $ftp_connection );

参数:该函数接受单个参数$ ftp_connection这是必需的。它指定FTP连接以关闭FTP连接

返回值:成功返回True, 失败返回False。

注意:

  • 此功能可用于PHP 4.0.0和更高版本。
  • 以下示例无法在在线IDE上运行。因此, 请尝试使用适当的ftp服务器名称在某些PHP托管服务器或localhost中运行。

下面的程序说明了PHP中的ftp_close()函数:

范例1:

<?php
  
// Connect to FTP server
$ftp_server = "localhost" ;
  
// Establishing ftp connection 
$ftp_connection = ftp_connect( $ftp_server ) 
     or die ( "Could not connect to $ftp_server" );
   
if ( $ftp_connection ) {
     echo "Successfully connected to the ftp server!" ;
      
     // Closing  connection
     if (ftp_close( $ftp_connection )) {
         echo "<br>Connection closed Successfully!" ;
     }
}
?>

输出如下:

Successfully connected to the ftp server!
Connection closed Successfully!

范例2:使用端口21连接到ftp服务器。

<?php
  
// Connect to FTP server
$ftp_server = "localhost" ;
  
// Establishing ftp connection 
$ftp_connection = ftp_connect( $ftp_server , 21) 
     or die ( "Could not connect to $ftp_server" );
   
if ( $ftp_connection ) {
     echo "Successfully connected to the ftp server!" ;
      
     // Closing  connection
     if (ftp_close( $ftp_connection )) {
         echo "<br>Connection closed Successfully!" ;
     }
}
?>

输出如下:

Successfully connected to the ftp server!
Connection closed Successfully!

参考:https://www.php.net/manual/en/function.ftp-close.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: