Change language

PHP ftp_delete () function

| |
Syntax:
ftp_delete ($ftp_connection, $file) 
Parameters:this function takes two parameters as specified above and described below:
  • $ftp_connection:Required. It specifies a pre-existing FTP connection that will be used to execute FTP commands or functions.
  • $file:Required. It specifies the path to the file on the server to be deleted.
Return Value:Returns TRUE on success or FALSE on failure.Notes :
  • This function is available for PHP 4.0.0 and above.
  • The following examples cannot be run in an online environment IDE. Therefore, try running the correct ftp server name, username and password on some PHP hosting server or localhost.
  • ★ ★ ★ Make sure the file provided as a parameter for deletion also exists you have permission to be deleted by the ftp user logged into the FTP connection, otherwise it will throw an error.
Example :  
// Connect to FTP server 
// Assign ftp server to a variable $ftp_server = "localhost" ;  
// Use correct ftp username $ftp_username = "user" ;  
// Use correct FTP password matching
// to the ftp username $ftp_userpass = "user" ;  
// Filename or filename with path
// file on the server to be deleted $file = "test.txt" ;  
// Setting up ftp connection $ftp_connection = ftp_connect ( $ftp_server ) or die ( "Could not connect to $ftp_server" ); if ( $ftp_connection ) { echo "successfully connected to the ftp server!" ; // Log in to an established connection // ftp username and password $login = ftp_login ( $ftp_connection , $ftp_username , $ftp_userpass ); if ( $login ) { // Success check login echo "
logged in successfully! "
; // ftp_delete() function to delete a file from the FTP server if (ftp_delete ( $ftp_connection , $file )) { echo "
deletion of"
. $file . "is successful." ; } else { echo "
Error while deleting the file"
. $file ; } } else { echo "
login failed!"
; } // Close connection if (ftp_close ( $ftp_connection )) { echo "
Connection closed Successfully!"
; } }
?>
Output:
successfully connected to the ftp server! logged in successfully! deletion of ./htdocs/test.txt is successful. Connection closed Successfully! 
If the file is deleted and run the same program again, provided that the file does not exist because it has already been deleted, an error will occur. the output will look like
successfully connected to the ftp server! logged in successfully! Error while deleting the file ./htdocs/test.txt Connection closed Successfully! 
Link: https://www.php.net/manual/en/function.ftp-delete.php

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically