Change language

PHP ftp_delete () function

| |
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!"
; } }
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! 


Best laptop for Sims 4


Best laptop for Zoom


Best laptop for Minecraft


Best laptop for engineering student


Best laptop for development


Best laptop for Cricut Maker


Best laptop for hacking


Best laptop for Machine Learning


Latest questions


psycopg2: insert multiple rows with one query

12 answers


How to convert Nonetype to int or string?

12 answers


How to specify multiple return types using type-hints

12 answers


Javascript Error: IPython is not defined in JupyterLab

12 answers


Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method