Paul Paul - 5 months ago 30
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?


Here you go:

$ftp = ftp_connect($host,$port,$timeout);

$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.