簡體   English   中英

如何使用PHP在FTP周圍復制文件

[英]How To Copy Files Around FTP Using PHP

我想使用php ftp函數將文件從一個文件夾復制到另一個文件夾。

例如

復制此文件: httpdocs / user_images / Services / File 1.jpg

要: httpdocs / user_images / folder11

我曾嘗試使用ftp_fput,但我沒有運氣。

也許一個鮮為人知的事實:PHP中的copy()函數可用於將文件復制到FTP服務器,盡管沒有使用特定於ftp的函數所獲得的控制。

換句話說,這可以做到這一點:

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

PHP.netftp_put的手冊頁:

<?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 ; 
} 
?>

復制功能無效。 您需要使用ftp_get()和ftp_put()函數才能完成此任務

除非您實際在服務器之間移動文件或PHP無法訪問的地方,否則請使用copy()(php)

<?
copy('httpdocs/user_images/Services/File 1.jpg', 'httpdocs/user_images/folder11/File 1.jpg');
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM