Uploading files through ftp in PHP
The following script uploads readme.txt file from the local server to the specified ftp server. If you want to make ftp uploader then you could use a form to take input from the user and if input name for the file was user_file then $file should be $file=$_FILES['user_file']['tmp_name'].
<?php
$ftp_server="example.com";
$ftp_user_name="user";
$ftp_user_pass="userpass";
// open video file for reading
$file = 'readme.txt';
$fp = fopen($file, 'r');
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//change to passive mode
ftp_pasv ( $conn_id , true );
// try to upload $file
if (ftp_fput($conn_id, 'uploaded_readme.txt', $fp, FTP_ASCII)) {
echo "Uploaded succeed";
}else{
echo "Upload Failed";
}
?>
Comments
Post a Comment