Go to English page

ViaThinkSoft CodeLib

Dieser Artikel befindet sich in der Kategorie:
CodeLibProgrammierhilfenPHP

Folgender Code erlaubt es, ein Verzeichnis per FTP hochzuladen:

<?php

function ftp_uploaddirectory($conn_id$local_dir$remote_dir)
{
  @
ftp_mkdir($conn_id$remote_dir);
  
$handle opendir($local_dir);
  while ((
$file readdir($handle)) !== false)
  {
    if ((
$file != '.') && ($file != '..'))
    {
      if (
is_dir($local_dir.$file))
      {
        
ftp_uploaddirectory($conn_id$local_dir.$file.'/'$remote_dir.$file.'/');
      }
      else
        
$f[] = $file;
    }
  }
  
closedir($handle);
  if (
count($f))
  {
    
sort($f);
    @
ftp_chdir($conn_id$remote_dir);
    foreach (
$f as $files)
    {
      
$from = @fopen("$local_dir$files"'r');
      @
ftp_fput($conn_id$files$fromFTP_BINARY);
    }
  }
}

?>

Beispiel:

<?php

$conn_id 
= @ftp_connect($server);
@
ftp_login ($conn_id$username$passwort);
ftp_uploaddirectory($conn_id'mydirectory/''theftpdirectory/');
@
ftp_quit($conn_id);

?>

Veröffentlichungen: http://us2.php.net/manual/en/function.ftp-fput.php#64691

Problematisch? "Fails if destination file exists. Delete first and it works." im darauffolgenden Kommentar.
Daniel Marschall
ViaThinkSoft Mitbegründer