Paul Paul - 4 months ago 20
PHP Question

Uploading file through FTP using PHP

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 directory) to some FTP host using PHP?

Answer

Here you go:

$ftp = ftp_connect($host,$port,$timeout);
ftp_login($ftp,$user,$pass);

$ret = ftp_nb_put($ftp, $dest_file, $source_file, FTP_BINARY, FTP_AUTORESUME);

while (FTP_MOREDATA == $ret)
    {
        // display progress bar, or someting
        $ret = ftp_nb_continue($ftp);
    }

// all done :-)

Error handling omitted for brevity.