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

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

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

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 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

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

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