Location: PHPKode > scripts > FTP Upload > ftp-upload/example.php
<?PHP

/************************************ WHAT IS IT? ***********************************************
 *
 *  Transfer file to server via FTP connection
 * 
 * @author David - alias 'kisPocok'
 * @author hide@address.com [ will.code.php.for.food+hide@address.com ]
 * @license Absolutly free! You can edit and share it. If you make a better version send to me!
 * @version 1.1
 * 
 * @category PHP CLASS
 * @package FILE UPLOAD WITH FTP
 * 
 * 
 *********************************** WHAT IS NEW? ***********************************************
 *
 * Version 1.1
 * 2008.07.01 SSL connection added
 * 
 * EXAMPLE TO USE IT:
 * Same as 'EXAMPLES' tab(bellow, second point, with a little difference. The fourth varius
 * at the object declare, this is the ssl connection activator. Set true to use ssl, or set 
 * false to off. Default value is false, so if you dont want to use it just skipp...
 * 
 * $ftp = new ftp("FTP_UNAME", "FTP_PASS", "FTP_ADDR", "DIR/", true1);
 * 
 * Learn more about 'ftp_ssl_connection'
 * http://hu.php.net/manual/en/function.ftp-ssl-connect.php
 * 
 * Note: Why this function may not exist 'ftp_ssl_connect()' is only available if OpenSSL support
 * is enabled into your version of PHP. If it's undefined and you've compiled FTP support then
 * this is why. For Windows you must compile your own PHP binaries to support this function. 
 * 
 * Install OpenSSL:
 * http://hu.php.net/manual/en/openssl.installation.php
 * 
 ************************************* EXAMPLES *************************************************
 * 
 * #1: Include the ftp class
 * require_once("ftp.class.php");
 * 
 * 
 * #2: Connection to server
 * $ftp = new ftp("FTP_USERNAME", "FTP_PASSWORD", "FTP_ADDRESS", "TARGET_DIRECTOR_IN_SERVER/");
 * 
 * 
 * #3: Upload a file
 * $ftp->upload_process("DIRECTORY_TO/YOUR_FILE_NAME.txt", "YOUR_FILE_WITH_NEW_NAME.txt");
 * 
 * 
 ************************************* F.A.Q. ***************************************************
 * 
 * Q: I want to upload more files with one connection, but i dont know how?
 * A: Just copy the third point! (#3) Like this:
 * $ftp->upload_process("DIRECTORY_TO/YOUR_FILE_NAME.txt", "YOUR_FILE_WITH_NEW_NAME_2.txt");
 * $ftp->upload_process("DIRECTORY_TO/YOUR_FILE_NAME.txt", "YOUR_FILE_WITH_NEW_NAME_3.txt");
 * 
 * 
 * Q: If I dont want to make new name for uploaded file?
 * A: Don't give the second var! Like this:
 * $ftp->upload_process("DIRECTORY_TO/YOUR_FILE_NAME.txt");
 * 
 * Q: I want to make my own debug process! How can i do that?
 * A: Its also easy. :) This is the code:
 * $result = $ftp->upload_file("DIRECTORY_TO/YOUR_FILE_NAME.txt", "YOUR_FILE_WITH_NEW_NAME.txt");
 *
 * $result is a boolean. There three way:
 * $result == false : Error occured when you want to upload
 * $result == NULL : Uploading file doesnt found!
 * $result == true : Everything is fine! You did it!
 * 
 * Q: What is 'TARGET_DIRECTOR_IN_SERVER'? 
 * A: Choose a location in ftp server like '/my_uploads/' or '/'.
 * ('/' is equal the root directory on server)
 * 
 * Q: If i dont give the 4th varius in ftp object what is the default data?
 * A: The default data is '/' (root directory)
 * 
 * 
 * Well done, You are ready! Enjoy!
 * 
 **/


require_once("ftp.class.php");

// simple connection to ftp
$ftp = new ftp("FTP_USERNAME", "FTP_PASSWORD", "FTP_ADDRESS", "TARGET_DIRECTOR_IN_SERVER/");

// ssl (secure) connection to ftp (READ: WHATS IS NEW for more details)
//$ftp = new ftp("FTP_USERNAME", "FTP_PASSWORD", "FTP_ADDRESS", "TARGET_DIRECTOR_IN_SERVER/" 1);

$ftp->upload_process("test.txt");

?>
Return current item: FTP Upload