note 91933 modified in function.ftp-put by danbrown
| From: | danbrown@php.net | Date: | Thu, 02 Jul 2009 12:32:05 +0000 |
| Subject: | note 91933 modified in function.ftp-put by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157813@lists.php.net to get a copy of this message | ||
I've seen two notes about a "ftp_copy" function but i think there's a
misinterpretation about what an "ftp_copy" function should do. For me , it should be
something like an ftp_rename that would keep the orginal file and clone it somewhere else on the
same ftp server, as for them they consider its purpose is to copy a local file to a distant ftp
..well .. as in FTP protocol there's no such thing as an FTP COPY command anyway, i think
you're free to interpret it as you want.
So here's my solution using ftp_put and ftp_get ..
<?php
// bool ftp_copy ( resource $ftp_stream , string $initialpath, string $newpath, string $imagename
)
function ftp_copy($conn_distant , $pathftp , $pathftpimg ,$img){
// on recupere l'image puis on la repose dans le nouveau folder
if(ftp_get($conn_distant, TEMPFOLDER.$img, $pathftp.'/'.$img ,FTP_BINARY)){
if(ftp_put($conn_distant, $pathftpimg.'/'.$img ,TEMPFOLDER.$img ,
FTP_BINARY)){
unlink(TEMPFOLDER.$img) ;
} else{
return false;
}
}else{
return false ;
}
return true ;
}
?>
--was--
I've seen two notes about a "ftp_copy" function but i think there's a
misinterpretation about what an "ftp_copy" function should do. For me , it should be
something like an ftp_rename that would keep the orginal file and clone it somewhere else on the
same ftp server, as for them they consider its purpose is to copy a local file to a distant ftp
..well .. as in FTP protocol there's no such thing as an FTP COPY command anyway, i think
you're free to interpret it as you want.
So here's my solution using ftp_put and ftp_get ..
bool ftp_copy ( resource $ftp_stream , string $initialpath, string $newpath, string $imagename )
function ftp_copy($conn_distant , $pathftp , $pathftpimg ,$img){
// on recupere l'image puis on la repose dans le nouveau folder
if(ftp_get($conn_distant, TEMPFOLDER.$img, $pathftp.'/'.$img ,FTP_BINARY)){
if(ftp_put($conn_distant, $pathftpimg.'/'.$img ,TEMPFOLDER.$img ,
FTP_BINARY)){
unlink(TEMPFOLDER.$img) ;
} else{
return false;
}
}else{
return false ;
}
return true ;
}
http://php.net/manual/en/function.ftp-put.php