Uploading file through FTP using PHP

后端 未结 6 1012
我在风中等你
我在风中等你 2020-12-13 06:54

I\'m curious how to upload file through FTP using PHP. Let\'s say I have upload form and user have uploaded a file. How to transfer the file (without moving from temp direct

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 07:49

    For anyone want to show a the upload progress while doing file transfers, this is a great library php-ftp-client to start :

    The code

    $interval = 1;
    $ftp->asyncDownload('illustrations/assets.zip', 'assets.zip', function ($stat) use ($interval) {
        ob_end_clean();
        ob_start();
    
        echo sprintf(
            "speed : %s KB/%ss | percentage : %s%% | transferred : %s KB | second now : %s 
    ", $stat['speed'], $interval, $stat['percentage'], $stat['transferred'], $stat['seconds'] ); ob_flush(); flush(); }, true, $interval);

    Result in the browser :

提交回复
热议问题