How To Copy Files Around FTP Using PHP

后端 未结 5 1175
感情败类
感情败类 2021-01-06 04:25

I am tring to copy a file from one folder to another using the php ftp functions.

e.g

Copy This File: httpdocs/user_images/Services/File 1.

相关标签:
5条回答
  • 2021-01-06 04:38

    From the manual page on ftp_put on PHP.net:

    <?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 ; 
    } 
    ?>
    
    0 讨论(0)
  • 2021-01-06 04:38

    Unless you're actually moving files between servers or to somewhere that PHP doesn't have access, use copy()(php)

    <?
    copy('httpdocs/user_images/Services/File 1.jpg', 'httpdocs/user_images/folder11/File 1.jpg');
    ?>
    
    0 讨论(0)
  • 2021-01-06 04:43

    Perhaps a little known fact: the copy() function in PHP can be used to copy files to an FTP server, though without as much control as you get by using the ftp-specific functions.

    In other words, this can do the job:

    if(copy('local/file.img', 'ftp://user:password@ftp.example.com/remote/dir/file.img')) {
      echo "It worked!!!";
    }
    

    http://php.net/manual/en/function.copy.php

    0 讨论(0)
  • 2021-01-06 04:48

    the Copy Function will not work. You need to use ftp_get () and ftp_put() functions in order to achieve this task

    0 讨论(0)
  • 2021-01-06 04:58

    file copy: http://us.php.net/manual/en/function.copy.php

    0 讨论(0)
提交回复
热议问题