2017-10-03 20 views
-1

ftp_putを使用して、php ftp経由で存在する場合、フォルダ/ファイルを上書きする方法。 デフォルトではファイルが上書きされません。これは、FTPサーバの実装に依存するであろう他のPHPのアップロードで既存のフォルダやファイルを上書きする方法は?

function ftp_putAll($conn_id, $folder, $remotedir) {       // Called from moveFolder function at line 161 // 
$d = dir($folder); 
while($file = $d->read()) {                // do this for each file in the directory 
    if ($file != "." && $file != "..") {            // to prevent an infinite loop 
     if (is_dir($folder."/".$file)) {            // do the following if it is a directory 
      if ([email protected]_chdir($conn_id, $remotedir."/".$file)) { 
       ftp_mkdir($conn_id, $remotedir."/".$file);        // create directories that do not yet exist 
      } 
      $stream_options = array('ftp' => array('overwrite' => true)); 
      $this->ftp_putAll($conn_id, $folder."/".$file, $remotedir."/".$file);  // recursive part 
     } else { 
      if(ftp_put($conn_id, $remotedir."/".$file, $folder."/".$file, FTP_ASCII)) { 
       $upload = ftp_put($conn_id, $remotedir."/".$file, $folder."/".$file, FTP_ASCII); 
       } 

{

}}

+1

は、文字通り最初のコメントを読んで関数のパラメータであります.php。 * ftp_put()は既存のファイルを上書きします。* – BenM

+0

私の場合、フォルダが上書きされませんでした。だから私は解決策を求めています –

+0

あなたのコードを共有してください。また、FTPユーザーのアクセス許可を確認します。 – BenM

答えて

0

。ファイルの上書きが許可されていない場合は、まずファイルを削除してからアップロードしてください。

0
function ftp_putAll($conn_id, $src_dir, $dst_dir){ 
    $d = dir($src_dir); 

    while($file = $d->read()) { // do this for each file in the directory 

     if ($file != "." && $file != "..") { // to prevent an infinite loop 

      if (is_dir($src_dir."/".$file)) { // do the following if it is a directory 

       if ([email protected]_chdir($conn_id, $dst_dir."/".$file)) { 

        ftp_mkdir($conn_id, $dst_dir."/".$file); // create directories that do not yet exist             
       } 


       ftp_putAll($conn_id, $src_dir."/".$file, $dst_dir."/".$file); // recursive part 

      } else { 


       @ftp_put($conn_id, $dst_dir."/".$file, $src_dir."/".$file, FTP_BINARY); 
      } 
     } 
    } 
    $d->close(); 
} 

上記のコードを試してください。 http://php.net/manual/en/function.ftp-put:後

接続ID、 ソースパス、 宛先パス

+0

違いは何ですか? –

関連する問題