用PHP写FTP文件上传类
2008-02-25 15:39
369 查看
<?php
/**
* @(#)dbutil.php
* PHP version 4.3.6
*
*
* Copyright 2008 SoftRoad. All Rights Reserved.
*
*====================================================================
* 変更履歴
*
* 新規作成 2008 年02月25日 蒋彪
*/
class FtpUtil{
/*FTPサバIP*/
var $ftp_server = "192.168.1.224";
/*FTPサパユーザー名*/
var $ftp_user = "mysearch";
/*FTPサパパースウード*/
var $ftp_pass = "mysearch";
/*源ファイル*/
var $source_file="../soft/11a1.jpg"; //源ファイル
/*目標ファイル*/
var $destination_file="/home/mysearch/11a1.jpg"; //目標ファイル
/*接続号*/
var $conn_id;
/**
*FTPサバIPを設定する。
*/
function setFtpServer($ftp_server){
$this->ftp_server=$ftp_server;
}
/**
*FTPサパユーザー名を設定する。
*/
function setFtpUser($ftp_user){
$this->ftp_user=$ftp_user;
}
/**
*FTPサバパースウードを設定する。
*/
function setFtpPass($ftp_pass){
$this->ftp_pass=$ftp_pass;
}
/**
*アップロードの源ファイルを設定する。
*/
function setSourceFile($source_file){
$this->source_file=$source_file;
}
/**
*アップロードの目標ファイルを設定する。
*/
function setDestFile($destination_file){
$this->destination_file=$destination_file;
}
/**
*FTPサバConnectionオブジェクトをゲットする。
*/
function connectFtpServer(){
// set up a connection or die
$conn_id = ftp_connect($this->ftp_server) or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, $this->ftp_user, $this->ftp_pass);
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $this->ftp_server for user $this->ftp_user_name";
exit;
} else {
echo "Connected to $this->ftp_server, for user $this->ftp_user_name";
}
$this->conn_id=$conn_id;
return $conn_id;
}
/**
*FTPサバConnectionをクローズする。
*/
function closeConnect(){
if($this->conn_id){
@ftp_close($this->conn_id);
}
}
/**
*ファイルをアップロード
*/
function upLoad(){
$upload = ftp_put($this->conn_id, $this->destination_file, $this->source_file, FTP_BINARY) or die("Couldn't connect to $this->ftp_server");
ftp_quit($this->conn_id);
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $this->source_file to $this->ftp_server as $this->destination_file";
}
}
}
?>
/**
* @(#)dbutil.php
* PHP version 4.3.6
*
*
* Copyright 2008 SoftRoad. All Rights Reserved.
*
*====================================================================
* 変更履歴
*
* 新規作成 2008 年02月25日 蒋彪
*/
class FtpUtil{
/*FTPサバIP*/
var $ftp_server = "192.168.1.224";
/*FTPサパユーザー名*/
var $ftp_user = "mysearch";
/*FTPサパパースウード*/
var $ftp_pass = "mysearch";
/*源ファイル*/
var $source_file="../soft/11a1.jpg"; //源ファイル
/*目標ファイル*/
var $destination_file="/home/mysearch/11a1.jpg"; //目標ファイル
/*接続号*/
var $conn_id;
/**
*FTPサバIPを設定する。
*/
function setFtpServer($ftp_server){
$this->ftp_server=$ftp_server;
}
/**
*FTPサパユーザー名を設定する。
*/
function setFtpUser($ftp_user){
$this->ftp_user=$ftp_user;
}
/**
*FTPサバパースウードを設定する。
*/
function setFtpPass($ftp_pass){
$this->ftp_pass=$ftp_pass;
}
/**
*アップロードの源ファイルを設定する。
*/
function setSourceFile($source_file){
$this->source_file=$source_file;
}
/**
*アップロードの目標ファイルを設定する。
*/
function setDestFile($destination_file){
$this->destination_file=$destination_file;
}
/**
*FTPサバConnectionオブジェクトをゲットする。
*/
function connectFtpServer(){
// set up a connection or die
$conn_id = ftp_connect($this->ftp_server) or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, $this->ftp_user, $this->ftp_pass);
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $this->ftp_server for user $this->ftp_user_name";
exit;
} else {
echo "Connected to $this->ftp_server, for user $this->ftp_user_name";
}
$this->conn_id=$conn_id;
return $conn_id;
}
/**
*FTPサバConnectionをクローズする。
*/
function closeConnect(){
if($this->conn_id){
@ftp_close($this->conn_id);
}
}
/**
*ファイルをアップロード
*/
function upLoad(){
$upload = ftp_put($this->conn_id, $this->destination_file, $this->source_file, FTP_BINARY) or die("Couldn't connect to $this->ftp_server");
ftp_quit($this->conn_id);
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $this->source_file to $this->ftp_server as $this->destination_file";
}
}
}
?>
相关文章推荐
- 利用PHP进行ftp上传文件
- PHP文件上传类应用
- php之文件上传类代码
- php面向对象之文件上传类
- php ftp文件上传与下载
- PHP封装的多文件上传类实例与用法详解
- php 多文件上传类
- php文件上传类
- PHP文件上传类封装
- php文件上传类程序代码
- 用php写 ftp文件上传函数教程
- (实用篇)PHP ftp上传文件操作类
- 一个完整的php文件上传类实例讲解
- brophp框架中文件上传类path设置要点
- PHP-简单分页和文件上传类
- Php文件上传类class.upload.php
- 在php中ftp上传文件到服务器的操作
- php下连接ftp实现文件的上传、下载、删除文件实例代码
- php可生成缩略图的文件上传类实例