首页 > 编程知识 正文

php中上传文件到ftp(php取ftp文件)

时间:2023-05-05 08:39:20 阅读:67292 作者:3642

ftp_size ()函数是PHP的内置函数,用于获取FTP服务器上特定文件的大小。

使用方法:

FTP_size($FTP_connection,$file_name );

参数:此函数接受以上两个参数和以下两个参数:

$ftp_connection:这是必需的参数。 指定文件已存在的要使用的FTP连接。

$file_name:必填参数。 指定远程服务器或FTP服务器上的文件或文件路径。

返回值:文件大小恢复正常,错误返回-1。

注意:

所有ftp服务器都不支持此功能。

此功能可在PHP 4.0.0或更高版本中使用。

以下示例无法在在线IDE中执行。 因此,请尝试使用相应的ftp服务器名称在某些PHP托管服务器或localhost上运行。

以下示例显示了PHP的ftp_size ()函数。

示例1 :

//connect to FTP服务器

//Use a correct ftp server

$ftp_server='localhost ';

//Use correct ftp username

$ftp_username='user ';

//usecorrectftppasswordcorresponding

//to the ftp username

$ftp_userpass='user ';

//filenameorpathtouploadtoftpserver

$file='shiva.jpg ';

//establishing FTP连接

$ FTP _ connection=FTP _ connect ($ FTP _ server ) )。

订单(couldnotconnectto $ FTP _ server );

if($FTP_connection ) {

echo ' successfullyconnectedtotheftpserver!' ;

//loggingintoestablishedconnectionwith

//FTP用户名称密码

$ log in=FTP _ log in ($ FTP _ connection、$ftp_username、$ftp_userpass );

if($login ) {

//checkingwhetherloggedinsuccessfullyornot

echo '

记录在successfully中! ';

//Size of the file using ftp_size () function。

$file _ size=FTP _ size ($ FTP _ connection,$ file );

if ($file_size!=-1 ()

echo '

$file is $file_size bytes.';

}

else {

echo '

错误获取文件大小. ';

}

}

else {

echo '

故障登录! ';

}

//echo FTP _ get _ option ($ FTP _ connection,1 );

//关闭ing连接

if(FTP_close($FTP_connection ) ) )

echo '

连接关闭的successfully! ';

}

}

输出:

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

//connect to FTP服务器

//Use a correct ftp server

$ftp_server='localhost ';

//Use correct ftp username

$ftp_username='user ';

//usecorrectftppasswordcorresponding

//to the ftp username

$ftp_userpass='user ';

//filenameorpathtouploadtoftpserver

$file='shiva.jpg ';

//establishing FTP连接

$ FTP _ connection=FTP _ connect $ FTP _ server,21 )

订单(couldnotconnectto $ FTP _ server );

if($FTP_connection ) {

echo ' successfullyconnectedtotheftpserver!' ;

//loggingintoestablishedconnectionwith

//FTP用户名称密码

$ log in=FTP _ log in ($ FTP _ connection、$ftp_username、$ftp_userpass );

if($login ) {

//checkingwhetherloggedinsuccessfullyornot

echo '

记录在successfully中! ';

//Size of the file using ftp_size () function。

$file _ size=FTP _ size ($ FTP _ connection,$ file );

if ($file_size!=-1 ()

echo '

$file is $file_size bytes.';

}

else {

echo '

错误获取文件大小. ';

}

}

else {

echo '

故障登录! ';

}

//echo FTP _ get _ option ($ FTP _ connection,1 );

//关闭ing连接

if(FTP_close($FTP_connection ) ) )

echo '

连接关闭的successfully! ';

}

}

输出:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。