当前位置:Gxlcms > PHP教程 > ftp_fput脚本在本地可以在服务器上就不行

ftp_fput脚本在本地可以在服务器上就不行

时间:2021-07-01 10:21:17 帮助过:9人阅读

因为是虚拟空间,无法修改php.ini文件,使用ftp上传大的视频文件到远程服务器,脚本如下:

$ftp_server= "xxxx.xxxx.com";
$ftp_user_name= "user";
$ftp_user_pass= "pass";
$local_file = "D:/Lyb_0/zmsgx.mp4";        //本地文件
$server_file = "htdocs/videos/zmsgx.mp4";  //待上传后文件所在路径
$conn_id = ftp_connect($ftp_server);         //联接FTP
$login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass) or die("Login error");  //登录
$fp=fopen($local_file,"r");
ftp_pasv($conn_id, true);   //开启被动模式传输
//上传参数
if(ftp_fput($conn_id,$server_file,$fp,FTP_BINARY)) {
    echo "Successfully uploaded $server_file\n";
}else{
    echo "There was a problem while uploading $file\n";
}
//关闭连接
ftp_close($conn_id);
fclose($fp);

在本地服务器上测试能传到远程服务器,但是这个脚本传到远程服务器上就不行了。

回复内容:

因为是虚拟空间,无法修改php.ini文件,使用ftp上传大的视频文件到远程服务器,脚本如下:

$ftp_server= "xxxx.xxxx.com";
$ftp_user_name= "user";
$ftp_user_pass= "pass";
$local_file = "D:/Lyb_0/zmsgx.mp4";        //本地文件
$server_file = "htdocs/videos/zmsgx.mp4";  //待上传后文件所在路径
$conn_id = ftp_connect($ftp_server);         //联接FTP
$login_result = ftp_login($conn_id,$ftp_user_name,$ftp_user_pass) or die("Login error");  //登录
$fp=fopen($local_file,"r");
ftp_pasv($conn_id, true);   //开启被动模式传输
//上传参数
if(ftp_fput($conn_id,$server_file,$fp,FTP_BINARY)) {
    echo "Successfully uploaded $server_file\n";
}else{
    echo "There was a problem while uploading $file\n";
}
//关闭连接
ftp_close($conn_id);
fclose($fp);

在本地服务器上测试能传到远程服务器,但是这个脚本传到远程服务器上就不行了。

人气教程排行