/ Published in: PHP
                    
                                        
Shows how to upload a single file to a FTP server.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
// FTP access parameters:
$host = 'ftp.example.org';
$usr = 'example_user';
$pwd = 'example_password';
// file to upload:
$local_file = './example.txt';
$ftp_path = '/data/example.txt';
// connect to FTP server (port 21)
// send access parameters
// turn on passive mode transfers (some servers need this)
// ftp_pasv ($conn_id, true);
// perform file upload
// check upload status:
print (!$upload) ? 'Cannot upload' : 'Upload complete';
print "\n";
/*
** Chmod the file (just as example)
*/
// If you are using PHP4 then you need to use this code:
// (because the "ftp_chmod" command is just available in PHP5+)
}
}
// try to chmod the new file to 666 (writeable)
print $ftp_path . " chmoded successfully to 666\n";
} else {
print "could not chmod $file\n";
}
// close the FTP stream
URL: http://www.jonasjohn.de/snippets/php/ftp-example.htm
Comments
 Subscribe to comments
                    Subscribe to comments
                
                