Home  >  Article  >  Backend Development  >  ftp_put() function in PHP

ftp_put() function in PHP

WBOY
WBOYforward
2023-08-23 23:41:061258browse

ftp_put() function in PHP

ftp_put() function uploads a file to an FTP server.

Syntax

ftp_put(con,remote_file,local_file,mode,beg_pos);

Parameters

  • con - FTP connection

  • remote_file - The file path to upload to

  • local_file - The file path to upload

  • mode - Transmission mode. Possible values ​​are:

    • FTP_ASCII, or

    • FTP_BINARY

  • beg_pos - The position where the upload starts

Return value

The ftp_put() function returns TRUE when successful and FALSE when failed.

Example

The following is an example of uploading a file to the server:

<?php
   $ftp_server = "192.168.0.4";
   $ftp_user = "tim";
   $ftp_pass = "wthbn#@121";
   $con = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
   $login = ftp_login($con, $ftp_user, $ftp_pass);
   $local_file = "localfile.txt";
   $my_serverfile = "serverfile.txt";
   if (ftp_put($ftp_conn, $my_serverfile, $local_file, FTP_ASCII)){
      echo "File uploaded!";
   } else {
      echo "Error in uploading the file!";
   }
   // close
   ftp_close($con);
?>

The above is the detailed content of ftp_put() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete