In this small post i will show you how to upload file on the ftp server using php. As we know there are many ftp function in php but whenever you want to upload file in ftp using php at that time ftp put function is useful.
Here, we will upload file to the FTP server in php.
ftp_put(ftp_conn, remote_file, local_file, mode, startpos);
ftp_conn - ftp_conn is required parameter and it is use to specifies the FTP connection.
remote_file - remote_file is required parameter and it is use to specifies the file path to upload path.
local_file - local_file is required parameter and it is use to specifies the path of the file to upload.
mode - mode is optional parameter and it is use to specifies the transfer mode. It has 2 possible values: 1) FTP_ASCII 2) FTP_BINARY.
startpos - startpos is optional parameter and it is use to specifies the position in the remote file to start uploading to.
<?php
// connect to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
//login to FTP server
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file = "localfile.txt";
// upload file
if (ftp_put($ftp_conn, "serverfile.txt", $file, FTP_ASCII))
{
echo "Successfully uploaded $file.";
}
else
{
echo "Error uploading $file.";
}
// close connection
ftp_close($ftp_conn);
?>
In this article, we will see how to integrate mailchimp API in laravel 9. Here we will learn how we can integr...
Aug-01-2022
Hello web developers! In this article, we'll see laravel 11 drag and drop file upload with dropzone js. He...
May-06-2024
In this article, we will see how to create web notifications in laravel 9 using pusher. Here, we will learn how to...
Feb-03-2023
In this tutorial, we will see how to get current week records in MySQL. Many times we need to get current week reco...
Feb-07-2022