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

WBOY
Release: 2016-06-06 20:32:31
Original
1402 people have browsed it

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

<code>$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);
</code>
Copy after login
Copy after login

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

回复内容:

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

<code>$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);
</code>
Copy after login
Copy after login

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

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template