How to Upload File on the FTP Server Using PHP

Websolutionstuff | May-20-2021 | Categories : PHP

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.

 

Syntax : 

 

ftp_put(ftp_conn, remote_file, local_file, mode, startpos);

 

Parameters : 

 

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.

 

Example :

 

<?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);
?>

 

Recommended Post
Featured Post
Laravel 8 Socialite Login With GitHub Account
Laravel 8 Socialite Login With...

In this tutorial we will see laravel 8 socialite login with github account. explains how to integrate OAuth github...

Read More

Oct-25-2021

How To Use Sweetalert2 In Laravel
How To Use Sweetalert2 In Lara...

Today we will learn how to use sweetalert2 In laravel, You can use sweetalert2 in laravel as well as php, ...

Read More

May-03-2021

How To Add Summernote Editor In Laravel
How To Add Summernote Editor I...

In this tutorial, I will let you know how to use summernote editor in laravel, In laravel or PHP many editors are a...

Read More

Jun-17-2020

Laravel 9 Autocomplete Search from Database
Laravel 9 Autocomplete Search...

In this article, we will see laravel 9 autocomplete search from the database. Using ajax autocomplete textbox in la...

Read More

Mar-14-2022