18
Sep

Upload files through ftp

Here we will see how we can upload the files from localhost to any server.

Before that we need the following details to upload the files through ftp.

a) Address of ftp server like myserver.com or ipaddress like 202.70.170.158

b) Username of ftp.

c) Password of ftp.

Now see each step to upload the files.

Example:

$file = //Filename which will be uploaded.

$myFileName = $_FILES[’Filedata’][’name’]; //Retrieve file path and file name

$myfile = $_FILES[’Filedata’][’name’]; //extract file name from path

$destination_file = "/".$myfile; //where you want to throw the file on the webserver

// connection settings

$ftp_server = " "; //address of ftp server (leave out ftp://)

$ftp_user_name = ""; // Username

$ftp_user_pass = ""; // Password

/*$ftp_server = ""; //address of ftp server (leave out ftp://)

$ftp_user_name = ""; // Username

$ftp_user_pass = ""; // Password*/

$conn_id = ftp_connect ($ftp_server); // set up basic connection

// login with username and password, or give invalid user message

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h1>You do not have access to this ftp server!</h1>");

$upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY); // upload the file

if (!$upload) { // check upload status

echo "<h2>FTP upload of $myFileName has failed!</h2> <br />";

}

else

{

echo “Uploaded successfully”

}

ftp_close($conn_id); // close the FTP stream

If you have any related query, please submit it in our FAQ section, we will try our best to get it solved by our expert Web Developers.

For specialized Web Development Services, visit TIS India, Web Development Company.


3 Comments

No comments yet.

LEAVE A COMMENT

Comments RSS Feed   TrackBack URL