今天是中秋了,祝各位快乐…
每逢佳节倍思亲,去年的今日,因为远隔千里我们不能相见,一年后的今天,她离我而去……
真的真的好想念她,想着和她在一起的每一天,每一份,每一秒……默默无语,唯有祝福…祝福我最爱的人,在没有我的日子里,多保重…
附上一个FTP类:
<?
/*
Class that connects to a FTP server to work with files and directores.
It features:
- connect to ftp server
- change current working dir
- create new empty file
- create new dir
- change access right to object
- send SITE command
- copy file
- move and rename file or dirs
- move uploaded file from TMP into CWD
- delete file or empty directory
- write into file
*/
class php_ftp_class{
var $user;
var $pw;
var $host;
var $root_dir;//root ftp dir of server
var $con_id;//descriptor on ftp connection
var $cwd;//current working dir
var $FTP_MODE=FTP_BYNARY;// FTP_ASCII | FTP_BYNARY
var $ERR=true;//must object display ftp errors
//constr.
function my_ftp($user="guest",$pw="guest",$host="localhost",$root=""){
$this->host=$host;
$this->user=$user;
$this->pw=$pw;
$this->root_dir=$root;
if($this->connect()){
$this->cwd=ftp_pwd($this->con_id);
}
}
//connect to ftp server
function connect(){
if($this->con_id=ftp_connect($this->host)){
if(ftp_login($this->con_id,$this->user,$this->pw))return true;
else $this->error("User <b>"".$this->user.""</b> cannot login to host <b>"".$this->host.""</b>");
}else $this->error("Connection with host <b>"".$this->host.""</b> not create!");
return false;
}
//close ftp connection
function close(){
ftp_quit($this->con_id);
}
//print error messages
function error($err_str=""){
if($this->ERR)echo "[".$err_str."]<br>\n";
}
//change current working dir
function cd($dir){
if(!@ftp_chdir($this->con_id,$dir)){
$this->error("Cannot view directory <b>"".$this->root_dir."/".$dir.""</b>!");
return false;
}
$this->cwd=@ftp_pwd($this->con_id);
return true;
}
//create new empty file
function mk_file($name){
if(file_exists($this->root_dir."/".$this->cwd."/".$name)){
$this->error("File <b>"".$this->root_dir."/".$this->cwd."/".$name.""</b> already exists!");
return false;
}else{
if(!$tmpfile=tempnam("/tmp","phpftptmp")){
$this->error("Can't create temp file?");
return false;
}elseif(!ftp_put($this->con_id,$name,$tmpfile,$this->FTP_MODE)){
$this->error("Can't create file <b>"".$this->root_dir."/".$this->cwd."/".$name.""</b>");
unlink($tmpfile);
return false;
}
}
unlink($tmpfile);
return true;
}
//create new dir
function mk_dir($name){
if(file_exists($this->root_dir."/".$this->cwd."/".$name)){
$this->error("Directory <b>"".$this->root_dir."/".$this->cwd."/".$name.""</b> already exists!");
return false;
}elseif(!ftp_mkdir($this->con_id,$name)){
$this->error("Cannot create directory <b>"".$this->root_dir."/".$this->cwd."/".$name.""");
return false;
}
return true;
}
//change access right to object
function set_perm($obj,$num){
//CHMOD 444 ftp.php3
if(!$this->site("CHMOD ".$num." ".$obj)){
$this->error("Cannot change permitions of object <b>"".$this->root_dir."/".$this->cwd."/".$obj.""</b>");
return false;
}
return true;
}
//send SITE command
function site($cmd){
if(!ftp_site($this->con_id, $cmd)){
$this->error("Cannot send site command <b>"".$cmd.""</b>");
return false;
}
return true;
}
//copy file
function copy($from,$to){
if(file_exists($this->root_dir."/".$to)){
$this->error("Object <b>"".$this->root_dir."/".$to.""</b> already exists!");
return false;
}
srand((double)microtime()*1000000);
$tmpfile=dirname(tempnam('',''))."/phpftptmp.".rand();
if(!copy($this->root_dir."/".$from,$tmpfile)){
$this->error("Can't create temp file?");
return false;
}elseif(!ftp_put($this->con_id,$to,$tmpfile,$this->FTP_MODE)){
$this->error("File <b>"".$this->root_dir."/".$from.""</b> can not copied to <b>"".$this->root_dir."/".$to.""</b>!");
return false;
}
return true;
}
//move object
function move($from,$to){
if(file_exists($this->root_dir."/".$to)){
$this->error("Object <b>"".$this->root_dir."/".$to.""</b> already exists!");
return false;
}
if(!ftp_rename($this->con_id,$from,$to)){
$this->error("Cannot move object <b>"".$this->root_dir."/".$from.""</b> to <b>"".$this->root_dir."/".$to.""</b>");
return false;
}
return true;
}