Home >Backend Development >PHP Tutorial >Tutorial on writing ftp file upload function in PHP_PHP tutorial
This tutorial is about using PHP to write ftp file upload functions. PHP is very powerful. You can use its own functions to implement FTP functions and realize the file upload function
This tutorial is about Tutorial on writing ftp file upload function using PHP tutorial. PHP is very powerful. You can use its own functions to implement the function of FTP and realize the file upload function. The following is a complete example
n";
function phpftp_top() {
echo "n";
echo " n";
echo "
echo "PHP FTP Client v1.4 n";
echo "echo "n";
echo "nn";
}function phpftp_bottom() {
n";
echo "nn";
echo "
echo "n" ;
echo "n";
}function phpftp_login() {
phpftp_top();
echo "n";
$ftp = @phpftp_connect( $phpftp_user, $phpftp_passwd );
if ( ! $ftp ) {
echo "FTP login failed!n";
echo "Start over?n";
phpftp_bottom();
} else {
if ( ! $phpftp_dir ) {
$phpftp_dir=ftp_pwd( $ftp );
}
if ( ! @ftp_chdir( $ftp, $phpftp_dir ) ) {
echo "Can't enter that directory!n";
$phpftp_dir=ftp_pwd( $ftp );
}
echo "Current directory: " . $phpftp_dir . "
n";
if ( $phpftp_dir == "/" ) {
$phpftp_dir="";
}
echo "n";
nn";
if ( $contents = ftp_nlist( $ftp, "." ) ) {
$d_i=0;
$f_i=0;
sort($contents);
for ( $i=0; $i < count( $contents ); $i++ ) {
$file_size = ftp_size( $ftp, $contents[$i] );
if ( $file_size == -1 ) {
$nlist_dirs[$d_i]=$contents[$i];
$d_i++;
} else {
$nlist_files[$f_i]=$contents[$i];
$nlist_filesize[$f_i]=$file_size;
$f_i++;
}
}
echo "nn"; n";
echo "Directories
n";
echo "n";
echo "nn";
echo "Files
n";
echo "n";
echo "
} else {
echo "Directory empty or not readable
n";
}
echo "
echo "n";
n";
echo "
echo "n";
n";
echo "
echo "nn";
echo "