Home > php教程 > php手册 > body text

php ftp_put 上传文件教程

WBOY
Release: 2016-06-13 10:09:42
Original
1815 people have browsed it

好了我们来看看用php自带的ftp函数做的文件上传吧,上传文件我们会用到ftp_put把文件传送到服务器下面有两个上传的简单实例。

好了我们来看看用php自带的ftp函数做的文件上传吧,上传文件我们会用到ftp_put把文件传送到服务器下面有两个上传的简单实例。

$file = 'somefile.txt';
$remote_file = 'readme.txt';
// 连接FTP服务器
$conn_id = ftp_connect($ftp_server);
//使用用户名、密码登陆
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//上传文件
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "成功上传 $file 文件n";
} else {
echo "上传 $file 文件失败n";
}
// 关闭ftp连接
ftp_close($conn_id);
?>

// 打开将要上传的文件
$file = 'demofile.txt';
$fp = fopen($file, 'r');

// 连接FTP服务器www.111cn.cn/
$conn_id = ftp_connect($ftp_server);
//登陆FTP服务器
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// 上传文件
if(ftp_fput($conn_id, $file, $fp, FTP_ASCII)) {
    echo "上传 $file 文件成功n";
} else {
    echo "上传 $file 文件失败n";
}

// 关闭FTP连接
ftp_close($conn_id);
//关闭打开的上传文件
fclose($fp);
?>

转载请注明www.111cn.cn/phper/php.html

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template